Vector .add() Replacing All Existing Elements as Well As Appending
I am developing with java SE on NetBeans 7.3.1
I am trying to read the first two elements of each line of a CSV file, put
them input a point variable of type Point2D and append each point to the
end of the Point2D vector coords. I use the following code.
br = new BufferedReader(new FileReader(inputFileName));
Vector<Point2D> coords = new Vector<Point2D>();
Point2D newPoint=new Point2D.Double(20.0, 30.0);
while ((strLine = br.readLine()) != null){
String [] subStrings = strLine.split(" ");
System.out.print("Substrings = " + subStrings[0] + ", " +
subStrings[1]);
System.out.println();
newPoint.setLocation(Float.parseFloat(subStrings[0]),
Float.parseFloat(subStrings[1]));
coords.add(newPoint);
}
coords.add(newPoint); appends the point as required but it also replaces
every existing element in coords with the new point. How do I stop the
existing elements being replaced by the new element?
No comments:
Post a Comment