SlideShare a Scribd company logo
JAVA
Collection classes
Prepared by
Miss. Arati A. Gadgil
Collections
•Collection represents a single unit of objects i.e. a group
•java.util package contains all the classes and interfaces for
Collection framework.
2
3
Methods
public boolean add(Object element)
is used to insert an element in this collection.
public boolean addAll(collection c)
is used to insert the specified collection elements in the
invoking collection.
public boolean remove(Object element)
is used to delete an element from this collection.
public boolean removeAll(Collection c)
is used to delete all the elements of specified collection
from the invoking collection.
4
public boolean retainAll(Collection c)
is used to delete all the elements of invoking collection except
the specified collection
public int size()
return the total number of elements in the collection.
public void clear()
removes the total no of element from the collection.
public boolean contains(object element)
is used to search an element.
public boolean containsAll(Collection c)
is used to search the specified collection in this collection 5
public Iterator iterator()
returns an iterator.
public Object[] toArray()
converts collection into array.
public boolean isEmpty()
checks if collection is empty.
public boolean equals(Object element)
matches two collection
public int hashCode()
returns the hashcode number for collection.
6
7
Iterator interface
Iterator interface provides the facility of iterating the elements
in forward direction only.
Methods
1.public boolean hasNext()
it returns true if iterator has more elements.
2.public object next()
it returns the element and moves the cursor pointer to the
next element.
3.public void remove()
it removes the last elements returned by the iterator. It is
rarely used.
Java ArrayList class
Java ArrayList class uses a dynamic array for storing the elements.It
extends AbstractList class and implements List interface.
Java ArrayList class can contain duplicate elements.
Java ArrayList class maintains insertion order.
Java ArrayList class is non synchronized.
Java ArrayList allows random access because array works at the index
basis.
In Java ArrayList class, manipulation is slow because a lot of shifting
needs to be occurred if any element is removed from the array list.
8
Java LinkedList class
Java LinkedList class uses doubly linked list to store the elements. It
extends the AbstractList class and implements List and Deque interfaces.
Java LinkedList class can contain duplicate elements.
Java LinkedList class maintains insertion order.
Java LinkedList class is non synchronized.
In Java LinkedList class, manipulation is fast because no shifting needs
to be occurred.
Java LinkedList class can be used as list, stack or queue
9
Difference between ArrayList and LinkedList
ArrayList LinkedList
1) ArrayList internally uses dynamic
array to store the elements.
LinkedList internally uses doubly linked
list to store the elements.
2) Manipulation with ArrayList
is slow because it internally uses array. If
any element is removed from the array,
all the bits are shifted in memory.
Manipulation with LinkedList
is faster than ArrayList because it uses
doubly linked list so no bit shifting is
required in memory.
3) ArrayList class can act as a list only
because it implements List only.
LinkedList class can act as a list and
queue both because it implements List
and Deque interfaces.
4) ArrayList is better for storing and
accessing data.
LinkedList is better for
manipulating data.
10
Java List Interface
List Interface is the subinterface of Collection.It contains methods to
insert and delete elements in index basis.It is a factory of ListIterator
interface.
Commonly used methods of List Interface:
public void add(int index,Object element);
public boolean addAll(int index,Collection c);
public object get(int Index position);
public object set(int index,Object element);
public object remove(int index);
public ListIterator listIterator();
public ListIterator listIterator(int i);
11
Java ListIterator Interface
ListIterator Interface is used to traverse the element in backward and
forward direction.
Commonly used methods of ListIterator Interface:
public boolean hasNext();
public Object next();
public boolean hasPrevious();
public Object previous();
12
Difference between List and Set
List can contain duplicate elements whereas Set contains unique
elements only.
Java HashSet class
uses hash table to store the elements. It extends AbstractSet class and
implements Set interface.
contains unique elements only
13
Java Queue Interface
Methods of Queue Interface
public boolean add(object);
public boolean offer(object);
public remove();
public poll();
public element();
public peek();
14
Java Map Interface
A map contains values based on the key i.e. key and value pair.Each
pair is known as an entry.Map contains only unique elements.
Commonly used methods of Map interface:
public Object put(object key,Object value):
is used to insert an entry in this map.
public void putAll(Map map)
is used to insert the specified map in this map.
public Object remove(object key)
is used to delete an entry for the specified key.
15
public Object get(Object key)
is used to return the value for the specified key.
public boolean containsKey(Object key)
is used to search the specified key from this map.
public boolean containsValue(Object value)
is used to search the specified value from this map.
public Set keySet()
returns the Set view containing all the keys.
public Set entrySet()
returns the Set view containing all the keys and values.
16
Entry
Entry is the subinterface of Map.So we will access it by Map.Entry
name.It provides methods to get key and value.
Methods of Entry interface:
public Object getKey()
is used to obtain key.
public Object getValue()
is used to obtain value
17
Sorting
We can sort the elements of:
String objects
Wrapper class objects
User-defined class objects
Method
public void sort(List list)
is used to sort the elements of List.List elements must be of
Comparable type.
18
19
Java Collections Framework
The Java Collections Framework is a collection of interfaces and classes
which helps in storing and processing the data efficiently. This
framework has several useful classes which have tons of useful functions
which makes a programmer task super easy.
20
Thank You
21
Ad

More Related Content

What's hot (20)

Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
Sony India Software Center
 
Collections framework in java
Collections framework in javaCollections framework in java
Collections framework in java
yugandhar vadlamudi
 
Collections In Java
Collections In JavaCollections In Java
Collections In Java
Binoj T E
 
Java Collections
Java CollectionsJava Collections
Java Collections
parag
 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
Prof. Erwin Globio
 
Collections Api - Java
Collections Api - JavaCollections Api - Java
Collections Api - Java
Drishti Bhalla
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets
Hitesh-Java
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
CPD INDIA
 
07 java collection
07 java collection07 java collection
07 java collection
Abhishek Khune
 
Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection framework
ankitgarg_er
 
5 collection framework
5 collection framework5 collection framework
5 collection framework
Minal Maniar
 
collection framework in java
collection framework in javacollection framework in java
collection framework in java
MANOJ KUMAR
 
List in java
List in javaList in java
List in java
nitin kumar
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVA
SAGARDAVE29
 
Collections in Java
Collections in JavaCollections in Java
Collections in Java
Khasim Cise
 
Java Collections
Java  Collections Java  Collections
Java Collections
Kongu Engineering College, Perundurai, Erode
 
Java collections
Java collectionsJava collections
Java collections
Hamid Ghorbani
 
Java 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional InterfacesJava 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional Interfaces
Ganesh Samarthyam
 
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!
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
Information Technology
 
Collections In Java
Collections In JavaCollections In Java
Collections In Java
Binoj T E
 
Java Collections
Java CollectionsJava Collections
Java Collections
parag
 
Collections Api - Java
Collections Api - JavaCollections Api - Java
Collections Api - Java
Drishti Bhalla
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets
Hitesh-Java
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
CPD INDIA
 
Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection framework
ankitgarg_er
 
5 collection framework
5 collection framework5 collection framework
5 collection framework
Minal Maniar
 
collection framework in java
collection framework in javacollection framework in java
collection framework in java
MANOJ KUMAR
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVA
SAGARDAVE29
 
Collections in Java
Collections in JavaCollections in Java
Collections in Java
Khasim Cise
 
Java 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional InterfacesJava 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional Interfaces
Ganesh Samarthyam
 
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!
 

Similar to Java collection (20)

Collection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshanCollection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshan
Zeeshan Khan
 
Advanced core java
Advanced core javaAdvanced core java
Advanced core java
Rajeev Uppala
 
Collection Framework-1.pptx
Collection Framework-1.pptxCollection Framework-1.pptx
Collection Framework-1.pptx
SarthakSrivastava70
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptx
SoniaKapoor56
 
java unit 4 pdf - about java collections
java unit 4 pdf - about java collectionsjava unit 4 pdf - about java collections
java unit 4 pdf - about java collections
aapalaks
 
Collections in Java Notes
Collections in Java NotesCollections in Java Notes
Collections in Java Notes
Shalabh Chaudhary
 
22.collections(1)
22.collections(1)22.collections(1)
22.collections(1)
Sirisha Chillakanti
 
Collections and generics
Collections and genericsCollections and generics
Collections and generics
Muthukumaran Subramanian
 
ArrayList.docx
ArrayList.docxArrayList.docx
ArrayList.docx
veerendranath12
 
Collections lecture 35 40
Collections lecture 35 40Collections lecture 35 40
Collections lecture 35 40
bhawna sharma
 
STRINGS IN JAVA
STRINGS IN JAVASTRINGS IN JAVA
STRINGS IN JAVA
LOVELY PROFESSIONAL UNIVERSITY
 
Nature Activities Binder _ by Slidesgo.pptx
Nature Activities Binder _ by Slidesgo.pptxNature Activities Binder _ by Slidesgo.pptx
Nature Activities Binder _ by Slidesgo.pptx
IllllBikkySharmaIlll
 
List interface in collections framework
List interface in collections frameworkList interface in collections framework
List interface in collections framework
Ravi Chythanya
 
Java collections notes
Java collections notesJava collections notes
Java collections notes
Surendar Meesala
 
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answeredU-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
zainmkhan20
 
collectionsframework210616084411 (1).pptx
collectionsframework210616084411 (1).pptxcollectionsframework210616084411 (1).pptx
collectionsframework210616084411 (1).pptx
ArunPatrick2
 
20CS305 Advance Java Programming Unit 1.ppt
20CS305 Advance Java Programming Unit 1.ppt20CS305 Advance Java Programming Unit 1.ppt
20CS305 Advance Java Programming Unit 1.ppt
logesswarisrinivasan
 
Collections - Lists & sets
Collections - Lists & setsCollections - Lists & sets
Collections - Lists & sets
RatnaJava
 
Linked list (java platform se 8 )
Linked list (java platform se 8 )Linked list (java platform se 8 )
Linked list (java platform se 8 )
charan kumar
 
oop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionoop lecture framework,list,maps,collection
oop lecture framework,list,maps,collection
ssuseredfbe9
 
Collection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshanCollection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshan
Zeeshan Khan
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptx
SoniaKapoor56
 
java unit 4 pdf - about java collections
java unit 4 pdf - about java collectionsjava unit 4 pdf - about java collections
java unit 4 pdf - about java collections
aapalaks
 
Collections lecture 35 40
Collections lecture 35 40Collections lecture 35 40
Collections lecture 35 40
bhawna sharma
 
Nature Activities Binder _ by Slidesgo.pptx
Nature Activities Binder _ by Slidesgo.pptxNature Activities Binder _ by Slidesgo.pptx
Nature Activities Binder _ by Slidesgo.pptx
IllllBikkySharmaIlll
 
List interface in collections framework
List interface in collections frameworkList interface in collections framework
List interface in collections framework
Ravi Chythanya
 
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answeredU-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
zainmkhan20
 
collectionsframework210616084411 (1).pptx
collectionsframework210616084411 (1).pptxcollectionsframework210616084411 (1).pptx
collectionsframework210616084411 (1).pptx
ArunPatrick2
 
20CS305 Advance Java Programming Unit 1.ppt
20CS305 Advance Java Programming Unit 1.ppt20CS305 Advance Java Programming Unit 1.ppt
20CS305 Advance Java Programming Unit 1.ppt
logesswarisrinivasan
 
Collections - Lists & sets
Collections - Lists & setsCollections - Lists & sets
Collections - Lists & sets
RatnaJava
 
Linked list (java platform se 8 )
Linked list (java platform se 8 )Linked list (java platform se 8 )
Linked list (java platform se 8 )
charan kumar
 
oop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionoop lecture framework,list,maps,collection
oop lecture framework,list,maps,collection
ssuseredfbe9
 
Ad

More from Arati Gadgil (16)

Java adapter
Java adapterJava adapter
Java adapter
Arati Gadgil
 
Java swing
Java swingJava swing
Java swing
Arati Gadgil
 
Java applet
Java appletJava applet
Java applet
Arati Gadgil
 
Java layoutmanager
Java layoutmanagerJava layoutmanager
Java layoutmanager
Arati Gadgil
 
Java awt
Java awtJava awt
Java awt
Arati Gadgil
 
Java stream
Java streamJava stream
Java stream
Arati Gadgil
 
Java thread
Java threadJava thread
Java thread
Arati Gadgil
 
Java networking
Java networkingJava networking
Java networking
Arati Gadgil
 
Java jdbc
Java jdbcJava jdbc
Java jdbc
Arati Gadgil
 
Java package
Java packageJava package
Java package
Arati Gadgil
 
Java interface
Java interfaceJava interface
Java interface
Arati Gadgil
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
Arati Gadgil
 
Java eventhandling
Java eventhandlingJava eventhandling
Java eventhandling
Arati Gadgil
 
Java exception
Java exception Java exception
Java exception
Arati Gadgil
 
Java class
Java classJava class
Java class
Arati Gadgil
 
Java basic
Java basicJava basic
Java basic
Arati Gadgil
 
Ad

Recently uploaded (20)

apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 

Java collection

  • 2. Collections •Collection represents a single unit of objects i.e. a group •java.util package contains all the classes and interfaces for Collection framework. 2
  • 3. 3
  • 4. Methods public boolean add(Object element) is used to insert an element in this collection. public boolean addAll(collection c) is used to insert the specified collection elements in the invoking collection. public boolean remove(Object element) is used to delete an element from this collection. public boolean removeAll(Collection c) is used to delete all the elements of specified collection from the invoking collection. 4
  • 5. public boolean retainAll(Collection c) is used to delete all the elements of invoking collection except the specified collection public int size() return the total number of elements in the collection. public void clear() removes the total no of element from the collection. public boolean contains(object element) is used to search an element. public boolean containsAll(Collection c) is used to search the specified collection in this collection 5
  • 6. public Iterator iterator() returns an iterator. public Object[] toArray() converts collection into array. public boolean isEmpty() checks if collection is empty. public boolean equals(Object element) matches two collection public int hashCode() returns the hashcode number for collection. 6
  • 7. 7 Iterator interface Iterator interface provides the facility of iterating the elements in forward direction only. Methods 1.public boolean hasNext() it returns true if iterator has more elements. 2.public object next() it returns the element and moves the cursor pointer to the next element. 3.public void remove() it removes the last elements returned by the iterator. It is rarely used.
  • 8. Java ArrayList class Java ArrayList class uses a dynamic array for storing the elements.It extends AbstractList class and implements List interface. Java ArrayList class can contain duplicate elements. Java ArrayList class maintains insertion order. Java ArrayList class is non synchronized. Java ArrayList allows random access because array works at the index basis. In Java ArrayList class, manipulation is slow because a lot of shifting needs to be occurred if any element is removed from the array list. 8
  • 9. Java LinkedList class Java LinkedList class uses doubly linked list to store the elements. It extends the AbstractList class and implements List and Deque interfaces. Java LinkedList class can contain duplicate elements. Java LinkedList class maintains insertion order. Java LinkedList class is non synchronized. In Java LinkedList class, manipulation is fast because no shifting needs to be occurred. Java LinkedList class can be used as list, stack or queue 9
  • 10. Difference between ArrayList and LinkedList ArrayList LinkedList 1) ArrayList internally uses dynamic array to store the elements. LinkedList internally uses doubly linked list to store the elements. 2) Manipulation with ArrayList is slow because it internally uses array. If any element is removed from the array, all the bits are shifted in memory. Manipulation with LinkedList is faster than ArrayList because it uses doubly linked list so no bit shifting is required in memory. 3) ArrayList class can act as a list only because it implements List only. LinkedList class can act as a list and queue both because it implements List and Deque interfaces. 4) ArrayList is better for storing and accessing data. LinkedList is better for manipulating data. 10
  • 11. Java List Interface List Interface is the subinterface of Collection.It contains methods to insert and delete elements in index basis.It is a factory of ListIterator interface. Commonly used methods of List Interface: public void add(int index,Object element); public boolean addAll(int index,Collection c); public object get(int Index position); public object set(int index,Object element); public object remove(int index); public ListIterator listIterator(); public ListIterator listIterator(int i); 11
  • 12. Java ListIterator Interface ListIterator Interface is used to traverse the element in backward and forward direction. Commonly used methods of ListIterator Interface: public boolean hasNext(); public Object next(); public boolean hasPrevious(); public Object previous(); 12
  • 13. Difference between List and Set List can contain duplicate elements whereas Set contains unique elements only. Java HashSet class uses hash table to store the elements. It extends AbstractSet class and implements Set interface. contains unique elements only 13
  • 14. Java Queue Interface Methods of Queue Interface public boolean add(object); public boolean offer(object); public remove(); public poll(); public element(); public peek(); 14
  • 15. Java Map Interface A map contains values based on the key i.e. key and value pair.Each pair is known as an entry.Map contains only unique elements. Commonly used methods of Map interface: public Object put(object key,Object value): is used to insert an entry in this map. public void putAll(Map map) is used to insert the specified map in this map. public Object remove(object key) is used to delete an entry for the specified key. 15
  • 16. public Object get(Object key) is used to return the value for the specified key. public boolean containsKey(Object key) is used to search the specified key from this map. public boolean containsValue(Object value) is used to search the specified value from this map. public Set keySet() returns the Set view containing all the keys. public Set entrySet() returns the Set view containing all the keys and values. 16
  • 17. Entry Entry is the subinterface of Map.So we will access it by Map.Entry name.It provides methods to get key and value. Methods of Entry interface: public Object getKey() is used to obtain key. public Object getValue() is used to obtain value 17
  • 18. Sorting We can sort the elements of: String objects Wrapper class objects User-defined class objects Method public void sort(List list) is used to sort the elements of List.List elements must be of Comparable type. 18
  • 19. 19 Java Collections Framework The Java Collections Framework is a collection of interfaces and classes which helps in storing and processing the data efficiently. This framework has several useful classes which have tons of useful functions which makes a programmer task super easy.
  • 20. 20