Pages

Key interfaces in java

What are the key interfaces in java?

There are 9 key interfaces in java:

1) Collection
2) List
3) Set
4) SortedSet
5) Navigable Set
6) Queue
7) Map
8) SortedMap
9) NavigableMap

Collection(I):
  • If we want to represent a group of individual objects as a single entity then we should go for collection
  • Collection interface defines the most common methods which are applicable for any collection object
      Methods:         

      boolean add(Object o)
      boolean addAll(Collection c)
      boolean remove(Object o)
      boolean removeAll(Collection c)
      boolean retainAll(Collection c) -- To remove all objects except those present in c
      void clear()
      boolean contains(Object o)
      boolean containsAll(Collection c)
      boolean  isEmpty()
      int size();
      Object[] toArray();
      Iterator iterator()
  • In general collection interface is considered as Root Interface of collection framework
LIST(I):
  • It is the child interface of collection
  • If we want to represent a group of individual objects as a single entity where duplicates are allowed and insertion order must be preserved, then we should go for List
SET(I):
  • It is the child interface of collection
  • If we want to represent a group of individual objects as a single entity where duplicates are not allowed and insertion order not required, then we should go for Set
Sortes Set(I):
  • It is the child interface of SET
  • If we want to represent a group of individual objects as a single entity where duplicates are not allowed and all objects should be inserted according to some sorting order, then we should go for Sorted Set.
Navigable Set(I):
  • It is the child interface of SortedSet.
  • It contains several methods for navigation purposes
  • To implement a navigable set, Tree set came 
Queue(I):
  • It follows FIFO i.e., First In First Out
  • Prior to processing, they should go for QUEUE
** Collection, List, sorted set, set, Navigable set, Queue ---Interfaces meant for representing a group of individual objects.

MAP(I): 
  • The map is not a child interface of collection.
  • If we want to represent a group of individual objects as a Key, Value pairs then we should go for MAP interface.
  • Both keys and values are objects only. Duplicate keys are not allowed but values can be duplicated.
Sorted Map(I):
  • It is the child interface of Map.
  • If we want to represent a group of key-value pairs according to some sorting order of keys then we should go for sorted Map.
Navigable Map(I):
  • It is the child interface of Sorted Map.
  • It defines several methods for navigating purposes.
  • TreeMap is the implementation class of the Navigable map.
Please comment below to feedback or ask questions.

No comments:

Post a Comment

Please comment below to feedback or ask questions.