Collection Framework PDF
Collection Framework PDF
Iterator is an interface that iterates that iterates the elements. It is used to traverse
the list and modify the elements. Iterator interface has three methods
• hasNext()
• next()
• remove()
Arrays
int rollno=1;
int rollno2=2;
.
int rollno100=100;
*******
Array
Advantage
Disadvantages
List
➔ It is an interface
➔ Can store Duplicate values and allows random access
➔ Elements are printed in an order.
➔ We can access any element from its index
➔ List are more likely array with dynamic length.
➔ Arraylist and linkedlists are the subclass used to implement list interface.
➔ List interface provides useful methods to add element at specific index,
remove, replace element based on index and to get a sub list using index.
Sets
➔ It is an interface
➔ Cannot store Duplicate values (ex: phone numbers)
➔ HashSet, TreeSet, LinkedHashSet are the Sub Class used to implement Set
interface-Parent class
➔ Doesn’t allow random access
➔ You can use iterator or foreach loop to traverse the elements of the set
Queue
Dequeue
Methods in Lists
➔ It is a subinterface of collection.
➔ It contains index based method to insert and delete elements.
Set
• Saves group of objects
• It is a non synchronized class
• Doesn’t allows duplicate values
• Doesn’t follow insertion order
• Doesn’t allow indexed based operations
• Set interface has
1. HashSet
2. LinkedHashSet
3. TreeSet
List
1. It maintains the order while insertion follows insertion order.
2. Allows duplicate values
3. Index based operations
HashSet LinkedHash TreeSet
Set
Duplicate no no no
Values
Insertion No-prints yes Ascending
order randomly order
(Sorting
order)
Synchroniz non non non
ed Synchroniz Synchronized Synchroniz
ed ed
Data Stores Hash Table Hash Table + Balanced
Double Tree
Linked List
Capacity 16 16 Based on
inserted
values it
will update
MAPS
Java.util.map;
Map is a Root interface.
Maps are not sub interfaces of collection.
Collection Map
Static Methods
sort()
reverse()
swap()
min()
max()