SlideShare uma empresa Scribd logo
1 de 21
Baixar para ler offline
- 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!!

Mais conteúdo relacionado

Mais procurados

Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets Hitesh-Java
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections frameworkRiccardo Cardin
 
Collections and its types in C# (with examples)
Collections and its types in C# (with examples)Collections and its types in C# (with examples)
Collections and its types in C# (with examples)Aijaz Ali Abro
 
Collections - Maps
Collections - Maps Collections - Maps
Collections - Maps Hitesh-Java
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVASAGARDAVE29
 
JAVA Collections frame work ppt
 JAVA Collections frame work ppt JAVA Collections frame work ppt
JAVA Collections frame work pptRanjith Alappadan
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate pptAneega
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteTushar B Kute
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Edureka!
 
L11 array list
L11 array listL11 array list
L11 array listteach4uin
 
Properties and indexers in C#
Properties and indexers in C#Properties and indexers in C#
Properties and indexers in C#Hemant Chetwani
 

Mais procurados (20)

Collections in Java Notes
Collections in Java NotesCollections in Java Notes
Collections in Java Notes
 
07 java collection
07 java collection07 java collection
07 java collection
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets
 
Java collection
Java collectionJava collection
Java collection
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
 
Java collections
Java collectionsJava collections
Java collections
 
Collections and its types in C# (with examples)
Collections and its types in C# (with examples)Collections and its types in C# (with examples)
Collections and its types in C# (with examples)
 
Collections framework in java
Collections framework in javaCollections framework in java
Collections framework in java
 
Collections - Maps
Collections - Maps Collections - Maps
Collections - Maps
 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
 
Java 8 Streams
Java 8 StreamsJava 8 Streams
Java 8 Streams
 
Java collections notes
Java collections notesJava collections notes
Java collections notes
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVA
 
JAVA Collections frame work ppt
 JAVA Collections frame work ppt JAVA Collections frame work ppt
JAVA Collections frame work ppt
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
 
L11 array list
L11 array listL11 array list
L11 array list
 
Properties and indexers in C#
Properties and indexers in C#Properties and indexers in C#
Properties and indexers in C#
 

Semelhante a Collections Api - Java

11000121065_NAITIK CHATTERJEE.ppt
11000121065_NAITIK CHATTERJEE.ppt11000121065_NAITIK CHATTERJEE.ppt
11000121065_NAITIK CHATTERJEE.pptNaitikChatterjee
 
oop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionoop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionssuseredfbe9
 
LJ_JAVA_FS_Collection.pptx
LJ_JAVA_FS_Collection.pptxLJ_JAVA_FS_Collection.pptx
LJ_JAVA_FS_Collection.pptxRaneez2
 
Java collections-interview-questions
Java collections-interview-questionsJava collections-interview-questions
Java collections-interview-questionsyearninginjava
 
Array list (java platform se 8 )
Array list (java platform se 8 )Array list (java platform se 8 )
Array list (java platform se 8 )charan kumar
 
Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdfObjective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdfadvancethchnologies
 
Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdfObjective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdfgiriraj65
 
Linked List Objective The purpose of this exercise is to cr.pdf
Linked List Objective The purpose of this exercise is to cr.pdfLinked List Objective The purpose of this exercise is to cr.pdf
Linked List Objective The purpose of this exercise is to cr.pdfadityacomputers001
 
1 list datastructures
1 list datastructures1 list datastructures
1 list datastructuresNguync91368
 
List interface in collections framework
List interface in collections frameworkList interface in collections framework
List interface in collections frameworkRavi Chythanya
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptxSoniaKapoor56
 

Semelhante a Collections Api - Java (20)

Java.util
Java.utilJava.util
Java.util
 
Collections framework
Collections frameworkCollections framework
Collections framework
 
22.collections(1)
22.collections(1)22.collections(1)
22.collections(1)
 
Advanced core java
Advanced core javaAdvanced core java
Advanced core java
 
11000121065_NAITIK CHATTERJEE.ppt
11000121065_NAITIK CHATTERJEE.ppt11000121065_NAITIK CHATTERJEE.ppt
11000121065_NAITIK CHATTERJEE.ppt
 
oop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionoop lecture framework,list,maps,collection
oop lecture framework,list,maps,collection
 
LJ_JAVA_FS_Collection.pptx
LJ_JAVA_FS_Collection.pptxLJ_JAVA_FS_Collection.pptx
LJ_JAVA_FS_Collection.pptx
 
Java collections-interview-questions
Java collections-interview-questionsJava collections-interview-questions
Java collections-interview-questions
 
16 containers
16   containers16   containers
16 containers
 
javacollections.pdf
javacollections.pdfjavacollections.pdf
javacollections.pdf
 
Collections and generics
Collections and genericsCollections and generics
Collections and generics
 
Array list (java platform se 8 )
Array list (java platform se 8 )Array list (java platform se 8 )
Array list (java platform se 8 )
 
ArrayList.docx
ArrayList.docxArrayList.docx
ArrayList.docx
 
Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdfObjective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdf
 
Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdfObjective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdf
 
Linked List Objective The purpose of this exercise is to cr.pdf
Linked List Objective The purpose of this exercise is to cr.pdfLinked List Objective The purpose of this exercise is to cr.pdf
Linked List Objective The purpose of this exercise is to cr.pdf
 
1 list datastructures
1 list datastructures1 list datastructures
1 list datastructures
 
Collection Framework-1.pptx
Collection Framework-1.pptxCollection Framework-1.pptx
Collection Framework-1.pptx
 
List interface in collections framework
List interface in collections frameworkList interface in collections framework
List interface in collections framework
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptx
 

Mais de Drishti Bhalla

Propositions - Discrete Structures
Propositions - Discrete Structures Propositions - Discrete Structures
Propositions - Discrete Structures Drishti Bhalla
 
Physical Layer Numericals - Data Communication & Networking
Physical Layer  Numericals - Data Communication & NetworkingPhysical Layer  Numericals - Data Communication & Networking
Physical Layer Numericals - Data Communication & NetworkingDrishti Bhalla
 
Determinants - Mathematics
Determinants - MathematicsDeterminants - Mathematics
Determinants - MathematicsDrishti Bhalla
 
Matrices - Mathematics
Matrices - MathematicsMatrices - Mathematics
Matrices - MathematicsDrishti Bhalla
 
Mid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsMid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsDrishti Bhalla
 
Unix Memory Management - Operating Systems
Unix Memory Management - Operating SystemsUnix Memory Management - Operating Systems
Unix Memory Management - Operating SystemsDrishti Bhalla
 
Airline Reservation System - Software Engineering
Airline Reservation System - Software EngineeringAirline Reservation System - Software Engineering
Airline Reservation System - Software EngineeringDrishti Bhalla
 
Performance Management and Feedback - SHRM
Performance Management and Feedback - SHRMPerformance Management and Feedback - SHRM
Performance Management and Feedback - SHRMDrishti Bhalla
 
Computer System Architecture - BUN instruction
Computer System Architecture - BUN instructionComputer System Architecture - BUN instruction
Computer System Architecture - BUN instructionDrishti Bhalla
 
King of acids -Sulphuric Acid H2SO4
King of acids -Sulphuric Acid H2SO4King of acids -Sulphuric Acid H2SO4
King of acids -Sulphuric Acid H2SO4Drishti Bhalla
 
Information Technology - System Threats
Information Technology - System ThreatsInformation Technology - System Threats
Information Technology - System ThreatsDrishti Bhalla
 
Software Metrics - Software Engineering
Software Metrics - Software EngineeringSoftware Metrics - Software Engineering
Software Metrics - Software EngineeringDrishti Bhalla
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsDrishti Bhalla
 
CNF & Leftmost Derivation - Theory of Computation
CNF & Leftmost Derivation - Theory of ComputationCNF & Leftmost Derivation - Theory of Computation
CNF & Leftmost Derivation - Theory of ComputationDrishti Bhalla
 
Fd & Normalization - Database Management System
Fd & Normalization - Database Management SystemFd & Normalization - Database Management System
Fd & Normalization - Database Management SystemDrishti Bhalla
 

Mais de Drishti Bhalla (16)

Propositions - Discrete Structures
Propositions - Discrete Structures Propositions - Discrete Structures
Propositions - Discrete Structures
 
Physical Layer Numericals - Data Communication & Networking
Physical Layer  Numericals - Data Communication & NetworkingPhysical Layer  Numericals - Data Communication & Networking
Physical Layer Numericals - Data Communication & Networking
 
Determinants - Mathematics
Determinants - MathematicsDeterminants - Mathematics
Determinants - Mathematics
 
Matrices - Mathematics
Matrices - MathematicsMatrices - Mathematics
Matrices - Mathematics
 
Holy Rivers - Hindi
Holy Rivers - HindiHoly Rivers - Hindi
Holy Rivers - Hindi
 
Mid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsMid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer Graphics
 
Unix Memory Management - Operating Systems
Unix Memory Management - Operating SystemsUnix Memory Management - Operating Systems
Unix Memory Management - Operating Systems
 
Airline Reservation System - Software Engineering
Airline Reservation System - Software EngineeringAirline Reservation System - Software Engineering
Airline Reservation System - Software Engineering
 
Performance Management and Feedback - SHRM
Performance Management and Feedback - SHRMPerformance Management and Feedback - SHRM
Performance Management and Feedback - SHRM
 
Computer System Architecture - BUN instruction
Computer System Architecture - BUN instructionComputer System Architecture - BUN instruction
Computer System Architecture - BUN instruction
 
King of acids -Sulphuric Acid H2SO4
King of acids -Sulphuric Acid H2SO4King of acids -Sulphuric Acid H2SO4
King of acids -Sulphuric Acid H2SO4
 
Information Technology - System Threats
Information Technology - System ThreatsInformation Technology - System Threats
Information Technology - System Threats
 
Software Metrics - Software Engineering
Software Metrics - Software EngineeringSoftware Metrics - Software Engineering
Software Metrics - Software Engineering
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
 
CNF & Leftmost Derivation - Theory of Computation
CNF & Leftmost Derivation - Theory of ComputationCNF & Leftmost Derivation - Theory of Computation
CNF & Leftmost Derivation - Theory of Computation
 
Fd & Normalization - Database Management System
Fd & Normalization - Database Management SystemFd & Normalization - Database Management System
Fd & Normalization - Database Management System
 

Último

FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 

Último (20)

FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

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();