Overview of Collection Framework
In this blog, I’m going to discuss the Overview of Collection Framework, its child interface, and the implementation classes.
So, a Collection is a group of similar or different types of objects and a Framework is nothing but an inbuilt architecture that consists of predefined interfaces, classes, and methods. All the data structures that are dynamic in nature mean we don’t have to specify the size of that collection at the time of creating that collection. Explore top Java interview questions and answers on the Collection Framework. Master essential concepts to excel in your next technical interview.
The overall collection framework is divided into two categories,
- Collection interface
- Collections class
All the classes and interfaces of the Collection Framework come under java.util package
The collection interface has 3 child interfaces,
- List the interface
- Set interface
- Map interface
Figure: Collection Framework
- List Interface
A list is a sequential or ordered type of data structure, in which data can be stored in sequential order
here, a List is an interface that comes under java.util package. The list has different Properties like 1. It preserves the insertion order 2. It allows duplicate values.
List has 4 implementation classes
a).ArrayList
b). LinkedList
c). Vector
d). Stack
a) ArrayList class
ArrayList is a collection of similar or different types of elements. ArrayList internally uses a dynamic array to store its elements. But, ArrayList is slower than LinkedList because in ArrayList elements get shifted in a forward or backward direction when we perform insertion and deletion operations respectively. ArrayList is Synchronized in nature. The default capacity of ArrayList before java8 is 10,, after java8 the capacity will be 0 means according to the no of elements capacity of ArrayList is decided
b) LinkedList class
LinkedList is the implementation class of the List interface which stores elements in the form of nodes.
LinkedList follows all the properties of the List interface
- It internally uses a doubly linked list to store the elements
- In LinkedList, the manipulation is fast because no shifting is required.
LinkedList is also non-synchronized. In LinkedList,it doesn’t have capacity because the nodes/elements in LinkedList are not stored in memory..each node only has a pointer to the next node
c) Vector class
Vector is the implementation class of the List interface. Vector is the same as ArrayList, which means like ArrayList it also uses a dynamic array to store its elements the only difference between both is ArrayList is non-synchronized whereas Vector is Synchronized(means at a time one thread gets executed on Vector object). The default capacity of Vector is 10
d) Stack class
Stack is a subclass of vector, the difference between Vector and Stack is we can perform insertion and deletion operations at any index means in the middle of the vector but In stack, insertion(push) and deletion(pop) operations are performed on top of stack only. Stack follows the principle of Last In First Out (LIFO).
For Free, Demo classes Call: 020-71173125
Registration Link: Click Here!
- Set Interface
Set is another type of collection that holds multiple objects like List but the difference between List and Set is it is an ordered type of collection whereas Set is an unordered type of collection means set stores data in random.
Properties of set
- It stores multiple objects in random order
- Set does NOT allow duplicate values.
Set has some child interfaces and classes
a). HashSet
b). LinkedHashSet
c). SortedSet
d). TreeSet
a) HashSet class
HashSet is the implementation class of Set Interface. HashSet is a combination of hashtable + set.
hashtable => hashtable is a table that stores the element in the form of key and value..here key must be unique, whereas the value can be duplicated)
HashSet follows both the properties of the set
b) LinkedHashSet class
LinkedHashSet is the child class of the HashSet class. LinkedHashSet is a combination of Linked list + hashtable + set. LinkedHashSet follows one property of the list(insertion order) and one of the set(not allowing duplicate elements)
c) SortedSet and NavigableSet interface
SorteSet is an interface which stores the elements in ascending order. NavigableSet is a child interface of the SortedSet interface. NavigableSet prints the Sorted set in reverse order.
d) TreeSet class
TreeSet is the implementation class for the SortedSet interface(does not allow duplicate elements)
- Map Interface
The map is a collection of elements that stores data in the form of a key and value pair and in the map, we have to specify elements in key and value pair format. A Map contains unique keys whereas values can be duplicated.
The map has some child interfaces and classes
a). HashMap
b). LinkedHashMap
c). SortedMap
d). TreeMap
a) HashMap class
HashMap is a combination of Hash table + Map
Properties of HashMap
- HAshMap doesn’t follow the insertion order
- It does not allow duplicate entries..
b) LinkedHashMap class
LinkedHashMap is a child class of HashMap. LinkedHashMap is a combination of linked list +Hash table + Map. LinkedHashMap follows one property of Set and one of List
- LinkedHAshMap follows the insertion order(property of list)
- It does not allow duplicate entries..(property of set)
c) SortedMap interface
SortedMAp is the child interface of the Map interface which sorts the entries of the map in ascending order based on the keys
d) TreeMap class
TreeMAp is an implementation class for the SortedMap interface
Do watch the video on Java: Click Here
Author:-
Pooja Nandode-Bhavsar
Call the Trainer and Book your free demo class for Java now!!!
© Copyright 2020 | SevenMentor Pvt Ltd.