Java Collections Framework

Image for post
Image for post

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.

It reduces the programming effort and increases performance while providing high interoperability.

Image for post
Image for post
  • 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

Then we have the Map interface which is separated from the Collections interface. It stores the values as key, value pairs.

Image for post
Image for post
  • 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.

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

Attributes of each

Image for post
Image for post

What are the common exception that we can get:

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

Senior Software Engineer — QA at WSO2

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store