SlideShare a Scribd company logo
- B Y
D I M P Y C H U G H ( 1 8 3 3 )
D R I S H T I B H A L L A ( 1 8 3 8 )
COLLECTIONS API
COLLECTION API
 Collection in java is a framework that provides an
architecture to store and manipulate the group of
objects.
 Java Collection Framework is a collection of many
interfaces( Set, List, Queue,Map) and classes (ArrayList,
Vector,LinkedList,PriorityQueue,HashSet,TreeSet,Tree
Map etc).
 All the operations that you perform on a data such as
searching, sorting, insertion, manipulation, deletion etc.
can be performed by Java Collections.
METHODS OF COLLECTION INTERFACE
No. Method Description
1 public boolean add(Object element) is used to insert an element in this
collection.
2 Object get(int index) Returns the element at the specified
position in the collection..
3 public boolean addAll(Collection c) is used to insert the specified collection
elements in the invoking collection.
4 public boolean remove(Object element) is used to delete an element from this
collection.
5 public int size() return the total number of elements in the
collection.
6 public void clear() removes the total no of element from the
collection.
7 public boolean contains(Object element) is used to search an element.
8 public boolean containsAll(Collection c) is used to search the specified collection in
this collection.
9 public Iterator iterator() returns an iterator.
10 public boolean isEmpty() checks if collection is empty.
11 public boolean equals(Object element) matches two collection.
INTERFACES
LIST- List of things
Allows duplicates
QUEUE- Things in FIFO manner
Allows duplicates & null values
SET- Unique Things
Allows null values
MAP – Things with unique key
Allows duplicate values
TRAVERSING TECHNIQUES
1) Using Iterator Interface
Iterator Interface is used to traverse the elements in forward direction
only. It has 2 main functions:
 public boolean hasNext()- It returns true if iterator has more
elements.
 public object next()- It returns the element and moves the cursor
pointer to the next element.
 For Example:
Iterator it=list.iterator();
while(it.hasNext())
{
System.out.println( " Element :" + it.next());
}
2) Using Enumeration Interface
Enumeration provides two methods to enumerate through the
elements.
 public boolean hasMoreElements()- returns true if there
are more elements to enumerate through otherwise it returns
false.
 public object nextElement()- returns the next element in
enumeration.
 For Example:
Enumeration e=v1.elements();
while(e.hasMoreElements())
{
System.out.println(e.nextElement());
}
3) Using ListIterator Inteface
ListIterator Interface is used to traverse the element in backward and
forward direction. It has 4 main functions:
 public boolean hasNext()- Returns true if this list iterator has
more elements when traversing the list in the forward direction
 public Object next()- Returns the next element in the list and
advances the cursor position.
 public boolean hasPrevious()- Returns true if this list iterator
has more elements when traversing the list in the reverse direction.
 public Object previous()- Returns the previous element in the
list and moves the cursor position backwards.
 Example for Traversing backwards
ListIterator itr=al.listIterator();
while(itr.hasPrevious())
{
System.out.println(itr.previous());
}
ARRAYLIST
 ArrayList is an inbuilt class that implements the List
interface.
 It uses dynamic array for storing the elements.
 It maintains insertion order.
 It takes NULL, TRUE, FALSE as elements of the list.
 In ArrayList, manipulation is slow because a lot of shifting
needs to be occurred if any element is removed from the
array list.
 Elements of ArrayList can be traversed using Iterator .
 Creating a new ArrayList
ArrayList al=new ArrayList();
VECTORS
 Vector implements the List Interface.
 It is similar to ArrayList as it also contains growable
array data structure, but with two differences:
I. Vector is synchronized- This means if one thread is
working on a Vector, no other thread can get a hold of
it. Unlike ArrayList, only one thread can perform an
operation on vector at a time.
II. Vector give poor performance- Operations on
elements gives poor performance as they are thread-
safe, the thread which works on Vector gets a lock on
it which makes other thread wait till the lock is
released.
 It maintains the insertion order.
 Allows duplicate elements in the list.
 Vector can be traversed by Enumerator or Iterator.
 Creating a new Vector
Vector v1=new Vector();
Additional Functions of Vector class
1) int capacity()- Returns the current capacity of this vector.
2) int indexOf(Object elem)- Searches for the first occurrence of the
given argument, testing for equality using the equals methodand -1 if the
vector does not contain this element.
LINKED LISTS
 LinkedList implements the List interface.
 Java LinkedList class uses doubly linked list to store the
elements.
 It can contain duplicate elements.
 Maintains insertion order.
 It is non synchronized.
 Java LinkedList class can be used as list, stack or queue.
 Linkedlist have same functions as that of collection interface.
 Creating a new LinkedList
LinkedList list=new LinkedList();
PRIORITY QUEUE
 PriorityQueue implements the Queue interface.
 Elements are added in any random order.
 Allows duplicate elements in the queue.
 It does not permit null elements.
 Head of the Queue is the least item in the order.
 A PriorityQueue is traversed using Iterator.
 Creating a new PriorityQueue
PriorityQueue p1=new PriorityQueue();
Additional Functions of PriorityQueue
1) Object peek()- This method retrieves, but does not remove, the
head of this queue, or returns null if this queue is empty.
2) Object poll()- This method retrieves and removes the head of
this queue, or returns null if this queue is empty.
HASHSET
 HashSet implements the Set interface. It uses hashtable to store
the elements.
 No insertion order is maintained.
 It permits null element.
 HashSet is traversed by Iterator.
 It contains unique elements only. But in case new objects are
formed i.e. memory locations are different , the hashset cannot
avoid duplicacy.
 Hashset have same functions as that of collection interface.
 Creating a new HashSet
HashSet set=new HashSet();
LINKED-HASHSET
 LinkedHashSet maintains a linked list of the entries in
the set, in the order in which they were inserted.
 It contains unique elements only like HashSet. It
extends HashSet class and implements Set interface.
 It is traversed by Iterator.
 The functions of LinkedHashset are same as Hashset.
 Creating a new LinkedHashSet
LinkedHashSet set=new LinkedHashSet();
TREESET
 It contains unique elements only like HashSet and implements Set interface .
 Elements are stored in sorted, ascending order.
 Access and retrieval times are quite fast, which makes TreeSet an excellent
choice when storing large amounts of sorted information that must be found
quickly.
 Creating a new TreeSet
TreeSet set=new TreeSet();
 Additional Functions of TreeSet
1) Object first()-Returns the first (lowest) element currently in this sorted set.
2) Object last()-Returns the last (highest) element currently in this sorted set.
3) SortedSet subSet(Object fromElement, Object toElement)-Returns
a view of the portion of this set whose elements range from fromElement,
inclusive, to toElement, exclusive.
HASHMAP
 HashMap maintains key and value pairs and are denoted as
HashMap<Key, Value> .
 It implements the Map interface.
 It can not take duplicate keys but can have duplicate values.
 It allows null key and null values.
 It maintains no order.
 It is mandatory to specify both key and value. Specifying key and
keeping value empty or vice-versa gives compile time error.
 HashMap is traversed by Iterator.
 It is non-synchronised.
 Creating a new HashMap
HashMap map=new HashMap();
 Additional Functions of HashMap
1. Set entrySet()- Returns a collection view of the mappings
contained in this map.
2. Object put(Object key, Object value)- Associates the
specified value with the specified key in this map.
3. Object remove(Object key)- Removes the mapping for
this key from this map if present.
4. boolean containsKey(Object key)- Returns true if this
map contains a mapping for the specified key.
LINKEDHASHMAP
 LinkedHashMap maintains a linked list of the entries
in the map, in the order in which they were inserted.
 It extends HashMap class and implements the Map
interface .
 It is same as HashMap instead maintains insertion
order of keys.
 It is traversed by Iterator.
 LinkedHashMap has same functions as that of
HashMap.
 Creating a new LinkedHashMap
LinkedHashMap map=new LinkedHashMap();
TREEMAP
 TreeMap class implements the Map interface by using a
tree.
 It can not take duplicate keys but can have duplicate values.
 It cannot have null key but can have multiple null values.
 A TreeMap provides an efficient means of storing key/value
pairs in sorted order, and allows rapid retrieval.
 TreeMap has same functions as that of HashMap.
 Creating a new TreeMap
TreeMap map=new TreeMap();
HASHTABLE
 HashTable implements the Map interface .
 Like HashMap, Hashtable stores key-value pairs. When
using a Hashtable, we specify an object that is used as a
key, and the value that we want linked to that key. The key
is then hashed, and the resulting hash code is used as the
index at which the value is stored within the table.
 It contains only unique elements.
 Any non-null object can be used as a key or as a value.
 Unlike HashMap, It is synchronized.It is thread-safe and
can be shared with many threads.
 Creating a new HashTable
HashTable map=new HashTable();
THANKYOU!!

More Related Content

PDF
Collections In Java
Binoj T E
 
PPT
Java Collections Framework
Sony India Software Center
 
PPT
Collection Framework in java
CPD INDIA
 
PDF
Java Collection framework
ankitgarg_er
 
ODP
Java Collections
parag
 
PPT
Java collection
Arati Gadgil
 
PPTX
Collections framework in java
yugandhar vadlamudi
 
PDF
5 collection framework
Minal Maniar
 
Collections In Java
Binoj T E
 
Java Collections Framework
Sony India Software Center
 
Collection Framework in java
CPD INDIA
 
Java Collection framework
ankitgarg_er
 
Java Collections
parag
 
Java collection
Arati Gadgil
 
Collections framework in java
yugandhar vadlamudi
 
5 collection framework
Minal Maniar
 

What's hot (20)

PDF
Java Collections Tutorials
Prof. Erwin Globio
 
PPTX
Java - Collections framework
Riccardo Cardin
 
PDF
Java Collections API
Alex Miller
 
PPT
Java collections concept
kumar gaurav
 
PDF
07 java collection
Abhishek Khune
 
ODP
Introduction to Java 8
Knoldus Inc.
 
PDF
Java 8 Lambda Expressions & Streams
NewCircle Training
 
PPTX
Method Overloading in Java
Sonya Akter Rupa
 
PDF
Java IO
UTSAB NEUPANE
 
PDF
Java 8 Lambda Expressions
Scott Leberknight
 
PDF
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Edureka!
 
PPT
JAVA Collections frame work ppt
Ranjith Alappadan
 
PDF
Collections in Java Notes
Shalabh Chaudhary
 
PPT
9. Input Output in java
Nilesh Dalvi
 
PPTX
collection framework in java
MANOJ KUMAR
 
PPT
Java 8 Streams
Manvendra Singh
 
PPTX
Standard Template Library
GauravPatil318
 
PPTX
Java 8 lambda
Manav Prasad
 
PPTX
Python-Encapsulation.pptx
Karudaiyar Ganapathy
 
Java Collections Tutorials
Prof. Erwin Globio
 
Java - Collections framework
Riccardo Cardin
 
Java Collections API
Alex Miller
 
Java collections concept
kumar gaurav
 
07 java collection
Abhishek Khune
 
Introduction to Java 8
Knoldus Inc.
 
Java 8 Lambda Expressions & Streams
NewCircle Training
 
Method Overloading in Java
Sonya Akter Rupa
 
Java IO
UTSAB NEUPANE
 
Java 8 Lambda Expressions
Scott Leberknight
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Edureka!
 
JAVA Collections frame work ppt
Ranjith Alappadan
 
Collections in Java Notes
Shalabh Chaudhary
 
9. Input Output in java
Nilesh Dalvi
 
collection framework in java
MANOJ KUMAR
 
Java 8 Streams
Manvendra Singh
 
Standard Template Library
GauravPatil318
 
Java 8 lambda
Manav Prasad
 
Python-Encapsulation.pptx
Karudaiyar Ganapathy
 
Ad

Similar to Collections Api - Java (20)

PPT
Collections
Rajkattamuri
 
PPT
Collections
Manav Prasad
 
PPT
collections
javeed_mhd
 
PPTX
collectionsframework210616084411 (1).pptx
ArunPatrick2
 
PPTX
LJ_JAVA_FS_Collection.pptx
Raneez2
 
PPT
Collections in Java
Khasim Cise
 
PPT
description of Collections, seaching & Sorting
mdimberu
 
DOC
Advanced core java
Rajeev Uppala
 
PPT
Java Collection fundamentals and Uses Unit
vinipant
 
PPTX
22CS305-UNIT-1.pptx ADVANCE JAVA PROGRAMMING
logesswarisrinivasan
 
PPT
java collections
javeed_mhd
 
PPT
12_-_Collections_Framework
Krishna Sujeer
 
PPTX
oop lecture framework,list,maps,collection
ssuseredfbe9
 
DOCX
Java collections notes
Surendar Meesala
 
PPTX
Javasession7
Rajeev Kumar
 
PPTX
22.collections(1)
Sirisha Chillakanti
 
PPT
JavaCollections.ppt
boopathirajaraja1
 
PPT
JavaCollections.ppt
Irfanhabeeb18
 
PPT
Best core & advanced java classes in mumbai
Vibrant Technologies & Computers
 
PDF
Collections
Linh Lê
 
Collections
Rajkattamuri
 
Collections
Manav Prasad
 
collections
javeed_mhd
 
collectionsframework210616084411 (1).pptx
ArunPatrick2
 
LJ_JAVA_FS_Collection.pptx
Raneez2
 
Collections in Java
Khasim Cise
 
description of Collections, seaching & Sorting
mdimberu
 
Advanced core java
Rajeev Uppala
 
Java Collection fundamentals and Uses Unit
vinipant
 
22CS305-UNIT-1.pptx ADVANCE JAVA PROGRAMMING
logesswarisrinivasan
 
java collections
javeed_mhd
 
12_-_Collections_Framework
Krishna Sujeer
 
oop lecture framework,list,maps,collection
ssuseredfbe9
 
Java collections notes
Surendar Meesala
 
Javasession7
Rajeev Kumar
 
22.collections(1)
Sirisha Chillakanti
 
JavaCollections.ppt
boopathirajaraja1
 
JavaCollections.ppt
Irfanhabeeb18
 
Best core & advanced java classes in mumbai
Vibrant Technologies & Computers
 
Collections
Linh Lê
 
Ad

More from Drishti Bhalla (16)

PPTX
Propositions - Discrete Structures
Drishti Bhalla
 
PDF
Physical Layer Numericals - Data Communication & Networking
Drishti Bhalla
 
PPT
Determinants - Mathematics
Drishti Bhalla
 
PPT
Matrices - Mathematics
Drishti Bhalla
 
PPTX
Holy Rivers - Hindi
Drishti Bhalla
 
PPTX
Mid point line Algorithm - Computer Graphics
Drishti Bhalla
 
ODP
Unix Memory Management - Operating Systems
Drishti Bhalla
 
PDF
Airline Reservation System - Software Engineering
Drishti Bhalla
 
PDF
Performance Management and Feedback - SHRM
Drishti Bhalla
 
PPTX
Computer System Architecture - BUN instruction
Drishti Bhalla
 
PPTX
King of acids -Sulphuric Acid H2SO4
Drishti Bhalla
 
PPTX
Information Technology - System Threats
Drishti Bhalla
 
PPTX
Software Metrics - Software Engineering
Drishti Bhalla
 
PDF
Binary Search - Design & Analysis of Algorithms
Drishti Bhalla
 
PPTX
CNF & Leftmost Derivation - Theory of Computation
Drishti Bhalla
 
PPTX
Fd & Normalization - Database Management System
Drishti Bhalla
 
Propositions - Discrete Structures
Drishti Bhalla
 
Physical Layer Numericals - Data Communication & Networking
Drishti Bhalla
 
Determinants - Mathematics
Drishti Bhalla
 
Matrices - Mathematics
Drishti Bhalla
 
Holy Rivers - Hindi
Drishti Bhalla
 
Mid point line Algorithm - Computer Graphics
Drishti Bhalla
 
Unix Memory Management - Operating Systems
Drishti Bhalla
 
Airline Reservation System - Software Engineering
Drishti Bhalla
 
Performance Management and Feedback - SHRM
Drishti Bhalla
 
Computer System Architecture - BUN instruction
Drishti Bhalla
 
King of acids -Sulphuric Acid H2SO4
Drishti Bhalla
 
Information Technology - System Threats
Drishti Bhalla
 
Software Metrics - Software Engineering
Drishti Bhalla
 
Binary Search - Design & Analysis of Algorithms
Drishti Bhalla
 
CNF & Leftmost Derivation - Theory of Computation
Drishti Bhalla
 
Fd & Normalization - Database Management System
Drishti Bhalla
 

Recently uploaded (20)

PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
The Future of Artificial Intelligence (AI)
Mukul
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 

Collections Api - Java

  • 1. - B Y D I M P Y C H U G H ( 1 8 3 3 ) D R I S H T I B H A L L A ( 1 8 3 8 ) COLLECTIONS API
  • 2. COLLECTION API  Collection in java is a framework that provides an architecture to store and manipulate the group of objects.  Java Collection Framework is a collection of many interfaces( Set, List, Queue,Map) and classes (ArrayList, Vector,LinkedList,PriorityQueue,HashSet,TreeSet,Tree Map etc).  All the operations that you perform on a data such as searching, sorting, insertion, manipulation, deletion etc. can be performed by Java Collections.
  • 3. METHODS OF COLLECTION INTERFACE No. Method Description 1 public boolean add(Object element) is used to insert an element in this collection. 2 Object get(int index) Returns the element at the specified position in the collection.. 3 public boolean addAll(Collection c) is used to insert the specified collection elements in the invoking collection. 4 public boolean remove(Object element) is used to delete an element from this collection. 5 public int size() return the total number of elements in the collection. 6 public void clear() removes the total no of element from the collection. 7 public boolean contains(Object element) is used to search an element. 8 public boolean containsAll(Collection c) is used to search the specified collection in this collection. 9 public Iterator iterator() returns an iterator. 10 public boolean isEmpty() checks if collection is empty. 11 public boolean equals(Object element) matches two collection.
  • 4. INTERFACES LIST- List of things Allows duplicates QUEUE- Things in FIFO manner Allows duplicates & null values SET- Unique Things Allows null values MAP – Things with unique key Allows duplicate values
  • 5. TRAVERSING TECHNIQUES 1) Using Iterator Interface Iterator Interface is used to traverse the elements in forward direction only. It has 2 main functions:  public boolean hasNext()- It returns true if iterator has more elements.  public object next()- It returns the element and moves the cursor pointer to the next element.  For Example: Iterator it=list.iterator(); while(it.hasNext()) { System.out.println( " Element :" + it.next()); }
  • 6. 2) Using Enumeration Interface Enumeration provides two methods to enumerate through the elements.  public boolean hasMoreElements()- returns true if there are more elements to enumerate through otherwise it returns false.  public object nextElement()- returns the next element in enumeration.  For Example: Enumeration e=v1.elements(); while(e.hasMoreElements()) { System.out.println(e.nextElement()); }
  • 7. 3) Using ListIterator Inteface ListIterator Interface is used to traverse the element in backward and forward direction. It has 4 main functions:  public boolean hasNext()- Returns true if this list iterator has more elements when traversing the list in the forward direction  public Object next()- Returns the next element in the list and advances the cursor position.  public boolean hasPrevious()- Returns true if this list iterator has more elements when traversing the list in the reverse direction.  public Object previous()- Returns the previous element in the list and moves the cursor position backwards.  Example for Traversing backwards ListIterator itr=al.listIterator(); while(itr.hasPrevious()) { System.out.println(itr.previous()); }
  • 8. ARRAYLIST  ArrayList is an inbuilt class that implements the List interface.  It uses dynamic array for storing the elements.  It maintains insertion order.  It takes NULL, TRUE, FALSE as elements of the list.  In ArrayList, manipulation is slow because a lot of shifting needs to be occurred if any element is removed from the array list.  Elements of ArrayList can be traversed using Iterator .  Creating a new ArrayList ArrayList al=new ArrayList();
  • 9. VECTORS  Vector implements the List Interface.  It is similar to ArrayList as it also contains growable array data structure, but with two differences: I. Vector is synchronized- This means if one thread is working on a Vector, no other thread can get a hold of it. Unlike ArrayList, only one thread can perform an operation on vector at a time. II. Vector give poor performance- Operations on elements gives poor performance as they are thread- safe, the thread which works on Vector gets a lock on it which makes other thread wait till the lock is released.
  • 10.  It maintains the insertion order.  Allows duplicate elements in the list.  Vector can be traversed by Enumerator or Iterator.  Creating a new Vector Vector v1=new Vector(); Additional Functions of Vector class 1) int capacity()- Returns the current capacity of this vector. 2) int indexOf(Object elem)- Searches for the first occurrence of the given argument, testing for equality using the equals methodand -1 if the vector does not contain this element.
  • 11. LINKED LISTS  LinkedList implements the List interface.  Java LinkedList class uses doubly linked list to store the elements.  It can contain duplicate elements.  Maintains insertion order.  It is non synchronized.  Java LinkedList class can be used as list, stack or queue.  Linkedlist have same functions as that of collection interface.  Creating a new LinkedList LinkedList list=new LinkedList();
  • 12. PRIORITY QUEUE  PriorityQueue implements the Queue interface.  Elements are added in any random order.  Allows duplicate elements in the queue.  It does not permit null elements.  Head of the Queue is the least item in the order.  A PriorityQueue is traversed using Iterator.  Creating a new PriorityQueue PriorityQueue p1=new PriorityQueue(); Additional Functions of PriorityQueue 1) Object peek()- This method retrieves, but does not remove, the head of this queue, or returns null if this queue is empty. 2) Object poll()- This method retrieves and removes the head of this queue, or returns null if this queue is empty.
  • 13. HASHSET  HashSet implements the Set interface. It uses hashtable to store the elements.  No insertion order is maintained.  It permits null element.  HashSet is traversed by Iterator.  It contains unique elements only. But in case new objects are formed i.e. memory locations are different , the hashset cannot avoid duplicacy.  Hashset have same functions as that of collection interface.  Creating a new HashSet HashSet set=new HashSet();
  • 14. LINKED-HASHSET  LinkedHashSet maintains a linked list of the entries in the set, in the order in which they were inserted.  It contains unique elements only like HashSet. It extends HashSet class and implements Set interface.  It is traversed by Iterator.  The functions of LinkedHashset are same as Hashset.  Creating a new LinkedHashSet LinkedHashSet set=new LinkedHashSet();
  • 15. TREESET  It contains unique elements only like HashSet and implements Set interface .  Elements are stored in sorted, ascending order.  Access and retrieval times are quite fast, which makes TreeSet an excellent choice when storing large amounts of sorted information that must be found quickly.  Creating a new TreeSet TreeSet set=new TreeSet();  Additional Functions of TreeSet 1) Object first()-Returns the first (lowest) element currently in this sorted set. 2) Object last()-Returns the last (highest) element currently in this sorted set. 3) SortedSet subSet(Object fromElement, Object toElement)-Returns a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive.
  • 16. HASHMAP  HashMap maintains key and value pairs and are denoted as HashMap<Key, Value> .  It implements the Map interface.  It can not take duplicate keys but can have duplicate values.  It allows null key and null values.  It maintains no order.  It is mandatory to specify both key and value. Specifying key and keeping value empty or vice-versa gives compile time error.  HashMap is traversed by Iterator.  It is non-synchronised.  Creating a new HashMap HashMap map=new HashMap();
  • 17.  Additional Functions of HashMap 1. Set entrySet()- Returns a collection view of the mappings contained in this map. 2. Object put(Object key, Object value)- Associates the specified value with the specified key in this map. 3. Object remove(Object key)- Removes the mapping for this key from this map if present. 4. boolean containsKey(Object key)- Returns true if this map contains a mapping for the specified key.
  • 18. LINKEDHASHMAP  LinkedHashMap maintains a linked list of the entries in the map, in the order in which they were inserted.  It extends HashMap class and implements the Map interface .  It is same as HashMap instead maintains insertion order of keys.  It is traversed by Iterator.  LinkedHashMap has same functions as that of HashMap.  Creating a new LinkedHashMap LinkedHashMap map=new LinkedHashMap();
  • 19. TREEMAP  TreeMap class implements the Map interface by using a tree.  It can not take duplicate keys but can have duplicate values.  It cannot have null key but can have multiple null values.  A TreeMap provides an efficient means of storing key/value pairs in sorted order, and allows rapid retrieval.  TreeMap has same functions as that of HashMap.  Creating a new TreeMap TreeMap map=new TreeMap();
  • 20. HASHTABLE  HashTable implements the Map interface .  Like HashMap, Hashtable stores key-value pairs. When using a Hashtable, we specify an object that is used as a key, and the value that we want linked to that key. The key is then hashed, and the resulting hash code is used as the index at which the value is stored within the table.  It contains only unique elements.  Any non-null object can be used as a key or as a value.  Unlike HashMap, It is synchronized.It is thread-safe and can be shared with many threads.  Creating a new HashTable HashTable map=new HashTable();