Pages

Java Collection Hierarchy And Major Interfaces

Collection interface:

  • To represent a group of element/objects as a single unit/entity, then programmer should consider Collection
  • Collection interface is considered as the root-interface of collection framework hierarchy
  • There is no concrete class which implements collection interface
  • Collection interface defines various common methods for
    1. Adding object to collection
    2. Removing an object from collection
    3. Checking size of collection
    4. Provide Iterator to iterate over collection
    5. Doing bulk operation
  • These methods can be used to operate on any collection objects
  • Present in java.util package and extends java.lang.Iterable interface

Java Collection Interfaces List




Java Collection Hierarchy




Serializable, Cloneable and RandomAccess

  • Every collection classes implements java.lang.Cloneable and java.io Serializable
  • ArrayList/Vector in addition to Cloneable/Serializable, implements java.util.RandomAccess for faster access
  • Read below points to understand why it implements these marker interfaces
Marker interfaceDescription
Random Accessto access any random element/objects with same speed
Cloneableto create a duplicate object or to clone an object
Serializableto transfer objects across network

Below listed interfaces extends Collection interface

  • List
  • Set
  • Queue

java.util.List

  • ArrayList
  • LinkedList
  • Vector
  • Stack

java.util.Set

  • HashSet
  • LinkedHashSet
  • SortedSet
  • NavigableSet
  • TreeSet

java.util.Queue

  • PriorityQueue
  • BlockingQueue
  • PriorityBlockingQueue
  • LinkedBlockingQueue