How does a Java Arraylist contains() method evalute objects?

Posted by mvid on Stack Overflow See other posts from Stack Overflow or by mvid
Published on 2010-04-15T03:43:33Z Indexed on 2010/04/15 3:53 UTC
Read the original article Hit count: 306

Filed under:
|
|
|

Say i create one object and add it to my ArrayList. If I then create another object with exactly the same constructor input, will the contain() method evaluate the two objects to be the same? Assume the constructor doesn't do anything funny with the input, and the variables stored in both objects are identical.

ArrayList<Thing> basket = new ArrayList<Thing>();
Thing thing = new Thing(100);
basket.add(thing);
Thing another = new Thing(100);
basket.contains(another); // true or false?

© Stack Overflow or respective owner

Related posts about java

Related posts about arraylist