Loop through array of objects inside the class
<p>I am having some trouble looping through an array with objects, inside the class. I wrote a little demo here so you can follow:</p>

<pre><code>Tank tanks[] = new Tank[2];
tanks[0] = new Tank();
tanks[1] = new Tank();
tanks[0].doStuff(tanks);

doStuff(Tank[] tanks) {
    for (int i = 0; i &lt; tanks.length; i++) {
        if (tanks[i].equals(this)) continue;
        // Do stuff
    }
}
</code></pre>

<p>So, I have an array with the type Tank. Then I call the method doStuff inside the Tank class. The method takes the array and loops through it. And then I want to do stuff to every tank that is not the current instance of the class. I hope you can make sense out of my code and this description.</p>

<p>The problem is that I get nullPointerException for <code>if (tanks[i].equals(this))</code></p>

<p>What am I doing wrong here?</p>
