How can I store objects into an ArrayList without them duplicating in Java? : <p>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:</p>

<pre><code>public static void main(String[] args) {
storage.addObject(2, 20, Jake, JE);
storage.addObject(5, 34, Kate, KI);
storage.addObject(3, 26, Joe, JL);
</code></pre>

<p>Then another class called storage will create and store these objects into an ArrayList</p>

<pre><code>public void addObject(int number, int age, String name, String code) {
Object newObject = new Object(number, age, name, code);
objects.add(newObject);
</code></pre>

<p>The problem that I am getting is that when I try </p>

<pre><code>System.out.println(objects);
</code></pre>

<p>Each bit of data in the array list is storing multiple objects so the output looks like this</p>

<pre><code>[2 20 Jake JE]
[2 20 Jake JE, 5 34 Kate KI]
[2 20 Jake JE, 5 34 Kate KI, 3 26 Joe JL]
</code></pre>

<p>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</p>

<pre><code>[2 20 Jake JE]
[5 34 Kate KI]
[3 26 Joe JL]
</code></pre>

<p>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</p>
