Showing posts with label equals(). Show all posts
Showing posts with label equals(). Show all posts

Thursday, 23 February 2012

The Collections framework

List classes


A List is an ordered collection, which allows positional access and search.

The classes implementing List are ordered by index position. An ArrayList enables fast iteration and constant speed positional access. A Vector is similar to ArrayList, only slower because it is synchronized. LinkedList allows fast insertion and deletion at the beginning or end. It is commonly used for implementing stacks and queues. For instance:

Thursday, 1 December 2011

The equals() method

We can use the == operator to compare the values of primitive variables and determine if they are equal. However, if object reference variables are compared using the == operator, it returns true only if the reference variables are referring to the same object. To check for the equality of two objects, the Object class provides the equals(Object obj) method, which can be overridden to return true for logically equal objects. The default implementation of the equals() method in the Object class returns true only if an object is