tags:

views:

56

answers:

1

Alright so I'm trying to get this class work:

public boolean hasPoint(Point p){

    for (int i=0; i<this.points.size(); i++){
        // Right here
        if(points[i].equals(p)){
            return true; 
        }

    }
    return false;     
}

However on line 3 I seem to be calling points as an array, but it's actually an arraylist. What am I doing wrong?

+5  A: 

To access elements of an ArrayList, use .get():

public boolean hasPoint(Point p){

    for (int i=0; i<this.points.size(); i++){
        if (points.get(i).equals(p)){
            return true; 
        }
    }

    return false;     
}

But if points is an ArrayList, you could just use ArrayList.contains() to the same effect:

public boolean hasPoint(Point p) {
    return points.contains(p);
}
NullUserException