so I'm trying to figure out how to print the actual contents, not memory locations, of my array list
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
public class hw2redo
{
public static void main(String args[]) throws FileNotFoundException
{
//Scan file for data
GeometricObject g = null;
BufferedReader file = new BufferedReader(new FileReader("file.txt"));
Scanner diskScanner = new Scanner(file);
//Create dynamic array list
ArrayList<GeometricObject> list = new ArrayList<GeometricObject>();
//Scan data and add data to list
while(diskScanner.hasNext())
{
String geolist = diskScanner.nextLine();
g = recreateObject(geolist);
list.add(g);
}
showObjects(list);
}
private static GeometricObject recreateObject(String data)
{
GeometricObject object = new GeometricObject(data);
return object;
}
private static void showObjects(ArrayList<GeometricObject> list)
{
for(GeometricObject o : list)
System.out.println(o);
}
}
class GeometricObject
{
public GeometricObject(String data) {
// TODO Auto-generated constructor stub
}
}
So here is my code. I have tried using the toString() and Arrays.toString() but they dont seem applicable for an arraylist (I tried because they worked on my regular arrays).
The output I'm recieving is
// Output
GeometricObject@55f96302
GeometricObject@3d4eac69
GeometricObject@42a57993
GeometricObject@75b84c92
GeometricObject@6bc7c054
GeometricObject@232204a1
which is good because I'm close, I just need to figure out how to print the actual contents.
The content I'm looking for in my file.txt is
Circle,green,false,4.0
Circle,blue,false,2.0
Circle,blue,true,7.0
Rectangle,orange,true,10.0,6.0
Rectangle,green,false,5.0,11.0
Rectangle,red,true,14.0,12.0
Any help would be much appreciated. Thanks!