Tuesday, 27 June 2023

Colection & Collections

What do you think Collection & Collections are same?

Answer is No Collection & Collections are not same.

Here we discussed how Collection & Collections are Difference.

Collection
  • Collection is Interface.
  • If we want to represent a group of individual object as a single entity than, we should go for Collection.
Collections
  • Collections is a class.
  • Collections is an Utility class present in Java.util  package to define several methods for Collection Objects.
  • For eg:- Sorting, Searching etc.
What is Collection Framework ?
  • It contains several classes & interfaces which can be used to represent a group of individual object as a single entity.
  • 9 Key Interface of Collection Framework.
  1. Collection
  2. List
  3. Set
  4. Sorted Set
  5. Navigable Set
  6. Queue
  7. Map
  8. Sorted Map
  9. Navigable Map
1.Collection (Interface)
  • If we want to represent a group of individual object as a single entity than we should go for Collection.
  • Collection Interface defines the most common methods which are applicable for any collection.
  • In general Collection Interface considered as Root Interface Collection Framework.
  • There is no Concrete class which implements collection directly.


2. List (Interface)
  • It is the Child Interface of Collection.
  • If you want to represent a group of individual Objects as a Single entity where, Duplication are allowed & Insertion order must be preserved than we should go for List(Interface).
  • Duplication are allowed.
  • Insertion Order must be Preserved


3. Set (Interface)
  • It is the Child Interface of Collection.
  • If you want to represent a group of individual Objects as a Single entity where, Duplication are not allowed & Insertion Order not required than we should go for Set(Interface).
  • Duplication are Not allowed.
  • Insertion order Not required.


4. Sorted Set(Interface)
  • It is the child Interface of Set(Interface).
  • If you want to represent a group of individual object as a Single entity where, Duplication are Not allowed Object should be Inserted according to some Sorting order than we should go for Sorted Set.
  • Duplication are Not allowed.
  • Object should be Inserted (Insertion & Sorting Order) are allowed.
5. Navigable Set(Interface)
  • It is the Child Interface of Sorted Set(Interface).
  • It Contains several methods for Navigable purpose.
6. Queue(Interface)
  • It is child Interface of Collection.
  • If we want to represent a group of individual objects Prior to Processing than, we should go for Queue.
  • Usually Queue follows FIFO(First In First Out) but based on Requirement we can implement our own Priority order also.
  • For eg:- 
  • Before Sending a Mail, all mail Id's we have to share in some data structure.
  • In which order we added Mail Id's in the some order only mail should be delivered.



Note:-
  • All the above Interface[Collection, List, Queue, Set, Sorted Set, Navigable Set] meant for representing a group of individual Objects.
  • If we want to represent a group of object as Key-Value-Pair than, we should go for Map.
7.  Map(Interface)
  • Map is Not Child interface of Collection.
  • Represent as a Key-value-Pair.
  • Both Key & Value are Object Only.
  • Duplicate keys are Not allowed but values can be Duplicated.
  • for eg:-




8. Sorted Map(Interface)
  • It is Child interface of Map.
  • If we want to represent a group of Key-Value-Pairs according to some Sorting order of keys than, we should go for sorted Map.
  • In sorted Map the Sorting should be based on Key but not based on  value.
9. Navigable Map(Interface)
  • It is the Child Interface of Sorted Map.
  • It defines several methods for Navigation purpose.
Note:- Following Legacy Character are present in Collection Framework.
  • Enumeration(Interface)
  • Dictionary(AC)
  • Vector(Class
  • HashTable(Class)
  • Properties(Class)
  • Stack(Interface)
What is the need of Cursor in Collection?
  • A group of individual object, we want get these object one by one from the collection than we will go for Cursor concept.
Three type of Cursor are present in Collection.
  • Enumeration(Interface)
  • Iterator(Interface)
  • ListIterator(Interface)
In Collection Two Utility Classes
  • Araays
  • Collections


No comments:

Post a Comment

Servlet in AEM/Sling Servlet

  What is Servlet? A servlet is a Java class that runs on the server side where the application resides. It acts as a middle layer between t...