Problem with adding to list inside a loop in java
<p>I wrote a code to check if an array is not in a list, then it should add it to another list. I used a linked list for this. But my problem is the program always add multiple copies of the current array and remove what's inside in the list before: My code is as follows:</p>

<pre><code>import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class Trial{

    public static void main(final String[] args){

        final List&lt;int[]&gt; G = new LinkedList&lt;int[]&gt;();
        final List&lt;int[]&gt; New = new LinkedList&lt;int[]&gt;();

        final int[] f = new int[2];

        for(int i = 0; i &lt; 2; i++){
            for(int j = 0; j &lt; 2; j++){
                f[0] = i;
                f[1] = j;
                // System.out.println("f is "+Arrays.toString(f));
                if(!(G.contains(f))){
                    System.out.println("current f is " + Arrays.toString(f));
                    // I print here in order to see what is f
                    New.add(f);
                    System.out.println("content of the list New");
                    // I print the list New to see its contents
                    for(int k = 0; k &lt; New.size(); k++){
                        System.out.println(Arrays.toString(New.get(k)));
                    }
                    System.out.println("finished printing the list New");
                }
            }
        }

    }

}
</code></pre>

<p>And this is the result I got after running:</p>

<pre><code>current f is [0, 0]
content of the list New
[0, 0]
finished printing the list New
current f is [0, 1]
content of the list New
[0, 1]
[0, 1]
finished printing the list New
current f is [1, 0]
content of the list New
[1, 0]
[1, 0]
[1, 0]
finished printing the list New
current f is [1, 1]
content of the list New
[1, 1]
[1, 1]
[1, 1]
[1, 1]
finished printing the list New
</code></pre>

<p>Please help!!!! </p>
