So i have some code that takes a bunch of data and creates objects from that data. Here is the pseudo code. The main class looks like this:
public static void main(String[] args) {
storage.addObject(2, 20, Jake, JE);
storage.addObject(5, 34, Kate, KI);
storage.addObject(3, 26, Joe, JL);
Then another class called storage will create and store these objects into an ArrayList
public void addObject(int number, int age, String name, String code) {
Object newObject = new Object(number, age, name, code);
objects.add(newObject);
The problem that I am getting is that when I try
System.out.println(objects);
Each bit of data in the array list is storing multiple objects so the output looks like this
[2 20 Jake JE]
[2 20 Jake JE, 5 34 Kate KI]
[2 20 Jake JE, 5 34 Kate KI, 3 26 Joe JL]
I don't know why it's repeating the objects but I am trying to make it so 1 object is in 1 part of the arrayList so the output looks like
[2 20 Jake JE]
[5 34 Kate KI]
[3 26 Joe JL]
The object creating class has a toString part so that all of the data gets converted to a string I'm not getting any compiling errors
storage
andObject
classes to clear your problem.System.out.println(objectToAdd);
instead?