The collection interface is the foundation upon which the collection framework is built. It declares the core methods that all collections will have. A class cast exception is generated when are objects is incompatible with another, Such as when an attempt is made to add an incompatible object to a collection. The following are methods defined in the collection interface.
Boolean add (object obj):
Adds object to the invoking collection. Returns true if object was added to the collection. Return false if object is already a member of the collection, or if the collection does not allow duplicates.
Boolean add all (collection c):
Adds all the elements of c to the invoking collection, Return true if the elements were added otherwise, return false.
Void clear ():
In this removes all the elements from the invoking collection.
Boolean contains (object obj):
Return true if object is an element of the invoking collection, otherwise return false.
Boolean contains all (collecton c):
Return true if the invoking collections contains all elements of c, otherwise return false.
Boolean equals (object obj):
Returns true if the invoking collection and object are equal, otherwise return false.
Int hash code ():
In this returns the hash code for the invoking collection.
Boolean is empty ():
Returns true if the invoking collection is empty, otherwise, return false.
Remove one instance of object from the invoking collection and returns true if the elements were removed, else return false.
Boolean removes all (collection c):
Removes all the elements from the invoking collection except those in c. Returns’ true if the elements were removed, otherwise returns false.
Boolean retain all:
Removes all elements from the invoking collection except those in c. return true, if the elements were removed otherwise, return false.
Int size ():
Returns the number of elements held in the invoking collection.