Wednesday 18 July 2018

What is Collections Framework in Java?

                   In this post, we will see Collection Framework in Java with Realtime Examples | Collections in Java with Examples with Coding | collections in java,collections in java interview questions,collection framework in java,collection framework interview questions,collection framework in java with realtime examples,what is collection framework in java,why collection framework is needed in java,collections in java with examples with coding,collections in java with examples,collections in java with realtime examples,collections in java with examples for beginners.

Watch following video:




Watch on YouTube: https://www.youtube.com/watch?v=2AXjepn67lo&t=2s


What is the necessity of Collections framework in Java? 
                  Java has supported multiple data structures. These data structures are implemented by predefined classes. For example, Stack data structure is implemented by class Stack. These classes have various methods. That's why, it becomes tedious and complex, to use these multiple data structures with their numerous methods. 
                   Hence Java has provided a common framework to access these data structures. It is known as Collections framework.

Structure of Collections framework: 
                   Collections framework has many Interfaces and Classes. Let us see, how it is implemented. Collections framework has a super interface known as Collection. It is extended in another interfaces List, Set, Queue, Map etc.



                    List interface is implemented in classes ArrayList, LinkedList. 

  • ArrayList is used as a dynamic array i.e. size of ArrayList is incremented automatically depending on requirement. 
  • LinkedList is used to maintain a linked list of elements.
                    Set inteface is implemented in classes HashSet, LinkedHashSet, TreeSet. All these classes stores unique elements. 

  • HashSet stores the elements in random sequence. 
  • LinkedHashSet stores the elements in the order of their insertion. 
  • TreeSet stores the elements in their increasing order.

                     Difference between List and Set is that List may have duplicate elements while Set has unique elements.

                     Queue interface is implemented in PriorityQueue class. It is used to maintain a queue of elements. Here, elements are inserted at one end while deleted from another end. 
                     Queue interface is extended in interface Deque. Deque is implemented in class ArrayDeque. It is used to maintain double ended queue i.e. insertion and deletion can be done at the both ends.
                    Map interface is implemented in classes HashMap, LinkedHashMap, TreeMap. All these classes stores elements in terms of key-value pair


  • HashMap stores the elements in random sequence. 
  • LinkedHashMap stores the elements in the order of their insertion. 
  • TreeMap stores the elements in increasing order of keys.

                   Find sample program on implementation of Collections framework in this link: https://www.comrevo.com/2018/08/program-on-collections-framework-in-java.html


No comments:

Post a Comment