Java Collections Framework

Collection: It is an object that represents a group of objects.

Java Collections Framework is all about how we store group of objects and manipulate them.

Why we need Collections

The Java Collection Framework in a nutshell

  • Set, List, and Queue interfaces extend the Collection interface.
  • The Set interface is implemented by HashSet, LinkedHashset classes. The Set interface is extended by the Sorted Set interface and it is implemented by the Treeset.
  • The List interface is implemented by ArrayList, Vector, and LinkedList classes.
  • The Queue interface is extended by Priority Queue and LinkedList classes. The LinkedList is implements both the List and the Queue interfaces.

Map Interface

  • The HashTable, Hashmap, and LinkedHashmap directly implement the Map interface.
  • The Sorted Map interface extends the Map interface and it is implemented by the Treemap.

The Common methods for Collections.

  • addAll()
  • contains()
  • remove()
  • removeAll()
  • containsAll()
  • size()
  • clear()
  • retain()
  • retainAll()

Attributes of each

What are the common exception that we can get:

  • NullPointer Exception
  • ClassCast Exception
  • IllegalArgumentException
  • IllegalStateException
  • UnsupportedOperationException

Senior Software Engineer — QA at WSO2