Collection Framework

Collection interface defines the most common methods useful for any collection object.

Following are the methods :

              Addition/Deletion methods :
    • add(Object obj) - add a single object to the collection
    • addAll(Collection coll) - add collection to the collection
    • remove(Object obj) - remove single object from the collection
    • removeAll(Collection coll) - remove collection from the collection
    • clear() - remove all objects from the collection
    • retainAll(Collection coll) - remove all objects except the objects in collection coll
               Utility methods :
    • isEmpty() - check if the collection is empty
    • size() - get the size of the collection
    • contains(Object obj) - check if object exists in the collection
    • containsAll(Collection coll) - check if objects in collection coll exists in the collection
    • toArray() - convert the collection into an array
    • iterator() - returns an Iterator object that can be used to iterate through the collection
As we saw in the previous post, collection interface is not implemented directly by  any class, it is only extended by  List, Queue and Set interfaces. Also, collection interface does not have any method for get() i.e. retrieval of objects.

Comments

Popular posts from this blog

Collection Framework - HashSet And LinkedHashSet class

Collection Framework - Cursors in Java

Hashed data structures