== vs equals method for Doubles
<p>I have this class</p>

<pre><code>public class Point {
    private Double[] coordinates;
    private int dimension;

    public Point(Double[] coordinates) {
        dimension = coordinates.length;
        this.coordinates = new Double[dimension];

        for(int i = 0; i &lt; dimension; i++)
            this.coordinates[i] = coordinates[i];


    }

    public Double getCoord(int n) {
        if(n &lt; 0 || n &gt; dimension -1 ){
            throw new RuntimeException("error de coordenadas");
        }
        return coordinates[n];
    }
    public int getDim() {
        return dimension;
    }

    public boolean equals(Object p1){
        if( (p1 instanceof Point) ){
            Point p = (Point) p1;
            int n = p.getDim();
            if(getDim() == n)
            {
                for(; n &gt; 0; n--)
                {
                    if( Double.valueOf(this.getCoord(n-1)) != Double.valueOf(p.getCoord(n-1)) ) // &lt;------- BAD LINE!
                    {
                        System.out.println("Checking coord " + (n-1));
                        System.out.println("Coord " + (n-1) + " p = " + Double.valueOf(this.getCoord(n-1)));
                        System.out.println("Coord " + (n-1) + " p2 = " + Double.valueOf(p.getCoord(n-1)));
                        return false;
                    }
                }
            }
            return true;
        }
        return false;
    }
}
</code></pre>

<p>And this main</p>

<pre><code>public class FigureTest {
    public static void main(String[] args){
        Double[] coord1 = {2.0,3.3};
        Double[] coord2 = {2.0,3.3};
        Point p = new Point(coord1);
        Point q = new Point(coord2);
        System.out.println(p.equals(q));
    }
}
</code></pre>

<p>I can't understand why this <code>p.equals(q)</code> returns false! It goes inside the <code>if( Double.valueOf(...</code> but then prints that both coordinates are equal. It's the same if I remove the <code>Double.valueOf</code>. The only way it worked was when I put <code>! if(this.getCoord(n-1).equal(p.getCoord(n-1))</code>, but I don't understand why the others don't work.</p>