ๅฐŠๆ•ฌ็š„ ๅพฎไฟกๆฑ‡็Ž‡๏ผš1ๅ†† โ‰ˆ 0.046166 ๅ…ƒ ๆ”ฏไป˜ๅฎๆฑ‡็Ž‡๏ผš1ๅ†† โ‰ˆ 0.046257ๅ…ƒ [้€€ๅ‡บ็™ปๅฝ•]
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

More Related Content

What's hot

Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection framework
ankitgarg_er
ย 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
Prof. Erwin Globio
ย 
L11 array list
L11 array listL11 array list
L11 array list
teach4uin
ย 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
Riccardo Cardin
ย 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets
Hitesh-Java
ย 
Collections in Java Notes
Collections in Java NotesCollections in Java Notes
Collections in Java Notes
Shalabh Chaudhary
ย 
Collections in Java
Collections in JavaCollections in Java
Collections in Java
Khasim Cise
ย 
Collections - Array List
Collections - Array List Collections - Array List
Collections - Array List
Hitesh-Java
ย 
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!
ย 
JAVA Collections frame work ppt
 JAVA Collections frame work ppt JAVA Collections frame work ppt
JAVA Collections frame work ppt
Ranjith Alappadan
ย 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
CPD INDIA
ย 
Java Thread Synchronization
Java Thread SynchronizationJava Thread Synchronization
Java Thread Synchronization
Benj Del Mundo
ย 
5 collection framework
5 collection framework5 collection framework
5 collection framework
Minal Maniar
ย 
Java I/O
Java I/OJava I/O
Java I/O
Jussi Pohjolainen
ย 
Java Stack Data Structure.pptx
Java Stack Data Structure.pptxJava Stack Data Structure.pptx
Java Stack Data Structure.pptx
vishal choudhary
ย 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVA
SAGARDAVE29
ย 
Arrays in java
Arrays in javaArrays in java
Arrays in java
Arzath Areeff
ย 
Collections - Maps
Collections - Maps Collections - Maps
Collections - Maps
Hitesh-Java
ย 
Java 8 Lambda and Streams
Java 8 Lambda and StreamsJava 8 Lambda and Streams
Java 8 Lambda and Streams
Venkata Naga Ravi
ย 
java 8 new features
java 8 new features java 8 new features
java 8 new features
Rohit Verma
ย 

What's hot (20)

Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection framework
ย 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
ย 
L11 array list
L11 array listL11 array list
L11 array list
ย 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
ย 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets
ย 
Collections in Java Notes
Collections in Java NotesCollections in Java Notes
Collections in Java Notes
ย 
Collections in Java
Collections in JavaCollections in Java
Collections in Java
ย 
Collections - Array List
Collections - Array List Collections - Array List
Collections - Array List
ย 
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...
ย 
JAVA Collections frame work ppt
 JAVA Collections frame work ppt JAVA Collections frame work ppt
JAVA Collections frame work ppt
ย 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
ย 
Java Thread Synchronization
Java Thread SynchronizationJava Thread Synchronization
Java Thread Synchronization
ย 
5 collection framework
5 collection framework5 collection framework
5 collection framework
ย 
Java I/O
Java I/OJava I/O
Java I/O
ย 
Java Stack Data Structure.pptx
Java Stack Data Structure.pptxJava Stack Data Structure.pptx
Java Stack Data Structure.pptx
ย 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVA
ย 
Arrays in java
Arrays in javaArrays in java
Arrays in java
ย 
Collections - Maps
Collections - Maps Collections - Maps
Collections - Maps
ย 
Java 8 Lambda and Streams
Java 8 Lambda and StreamsJava 8 Lambda and Streams
Java 8 Lambda and Streams
ย 
java 8 new features
java 8 new features java 8 new features
java 8 new features
ย 

Similar to Java collection

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 collections
Java collectionsJava collections
Java collections
Hamid Ghorbani
ย 
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
ย 
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
ย 
Java.util
Java.utilJava.util
Java.util
Ramakrishna kapa
ย 
Collections framework
Collections frameworkCollections framework
Collections framework
Anand Buddarapu
ย 
javacollections.pdf
javacollections.pdfjavacollections.pdf
javacollections.pdf
ManojKandhasamy1
ย 
Collections
CollectionsCollections
Collections
sagsharma
ย 

Similar to Java collection (20)

Collection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshanCollection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshan
ย 
Advanced core java
Advanced core javaAdvanced core java
Advanced core java
ย 
Collection Framework-1.pptx
Collection Framework-1.pptxCollection Framework-1.pptx
Collection Framework-1.pptx
ย 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptx
ย 
Java collections
Java collectionsJava collections
Java collections
ย 
22.collections(1)
22.collections(1)22.collections(1)
22.collections(1)
ย 
Collections and generics
Collections and genericsCollections and generics
Collections and generics
ย 
ArrayList.docx
ArrayList.docxArrayList.docx
ArrayList.docx
ย 
Collections lecture 35 40
Collections lecture 35 40Collections lecture 35 40
Collections lecture 35 40
ย 
STRINGS IN JAVA
STRINGS IN JAVASTRINGS IN JAVA
STRINGS IN JAVA
ย 
Nature Activities Binder _ by Slidesgo.pptx
Nature Activities Binder _ by Slidesgo.pptxNature Activities Binder _ by Slidesgo.pptx
Nature Activities Binder _ by Slidesgo.pptx
ย 
List interface in collections framework
List interface in collections frameworkList interface in collections framework
List interface in collections framework
ย 
Java collections notes
Java collections notesJava collections notes
Java collections notes
ย 
Collections - Lists & sets
Collections - Lists & setsCollections - Lists & sets
Collections - Lists & sets
ย 
Linked list (java platform se 8 )
Linked list (java platform se 8 )Linked list (java platform se 8 )
Linked list (java platform se 8 )
ย 
oop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionoop lecture framework,list,maps,collection
oop lecture framework,list,maps,collection
ย 
Java.util
Java.utilJava.util
Java.util
ย 
Collections framework
Collections frameworkCollections framework
Collections framework
ย 
javacollections.pdf
javacollections.pdfjavacollections.pdf
javacollections.pdf
ย 
Collections
CollectionsCollections
Collections
ย 

More from Arati Gadgil

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
ย 

More from Arati Gadgil (16)

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

Recently uploaded

Keynote given on June 24 for MASSP at Grand Traverse City
Keynote given on June 24 for MASSP at Grand Traverse CityKeynote given on June 24 for MASSP at Grand Traverse City
Keynote given on June 24 for MASSP at Grand Traverse City
PJ Caposey
ย 
pol sci Election and Representation Class 11 Notes.pdf
pol sci Election and Representation Class 11 Notes.pdfpol sci Election and Representation Class 11 Notes.pdf
pol sci Election and Representation Class 11 Notes.pdf
BiplabHalder13
ย 
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
220711130100 udita Chakraborty  Aims and objectives of national policy on inf...220711130100 udita Chakraborty  Aims and objectives of national policy on inf...
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
Kalna College
ย 
Creating Images and Videos through AI.pptx
Creating Images and Videos through AI.pptxCreating Images and Videos through AI.pptx
Creating Images and Videos through AI.pptx
Forum of Blended Learning
ย 
A Quiz on Drug Abuse Awareness by Quizzito
A Quiz on Drug Abuse Awareness by QuizzitoA Quiz on Drug Abuse Awareness by Quizzito
A Quiz on Drug Abuse Awareness by Quizzito
Quizzito The Quiz Society of Gargi College
ย 
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptxCapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapitolTechU
ย 
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
ShwetaGawande8
ย 
Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...
Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...
Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...
biruktesfaye27
ย 
Get Success with the Latest UiPath UIPATH-ADPV1 Exam Dumps (V11.02) 2024
Get Success with the Latest UiPath UIPATH-ADPV1 Exam Dumps (V11.02) 2024Get Success with the Latest UiPath UIPATH-ADPV1 Exam Dumps (V11.02) 2024
Get Success with the Latest UiPath UIPATH-ADPV1 Exam Dumps (V11.02) 2024
yarusun
ย 
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
220711130083 SUBHASHREE RAKSHIT  Internet resources for social science220711130083 SUBHASHREE RAKSHIT  Internet resources for social science
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
Kalna College
ย 
Information and Communication Technology in Education
Information and Communication Technology in EducationInformation and Communication Technology in Education
Information and Communication Technology in Education
MJDuyan
ย 
IoT (Internet of Things) introduction Notes.pdf
IoT (Internet of Things) introduction Notes.pdfIoT (Internet of Things) introduction Notes.pdf
IoT (Internet of Things) introduction Notes.pdf
roshanranjit222
ย 
Decolonizing Universal Design for Learning
Decolonizing Universal Design for LearningDecolonizing Universal Design for Learning
Decolonizing Universal Design for Learning
Frederic Fovet
ย 
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
Kalna College
ย 
Bแป˜ Bร€I TแบฌP TEST THEO UNIT - FORM 2025 - TIแบพNG ANH 12 GLOBAL SUCCESS - KรŒ 1 (B...
Bแป˜ Bร€I TแบฌP TEST THEO UNIT - FORM 2025 - TIแบพNG ANH 12 GLOBAL SUCCESS - KรŒ 1 (B...Bแป˜ Bร€I TแบฌP TEST THEO UNIT - FORM 2025 - TIแบพNG ANH 12 GLOBAL SUCCESS - KรŒ 1 (B...
Bแป˜ Bร€I TแบฌP TEST THEO UNIT - FORM 2025 - TIแบพNG ANH 12 GLOBAL SUCCESS - KรŒ 1 (B...
Nguyen Thanh Tu Collection
ย 
How to Create User Notification in Odoo 17
How to Create User Notification in Odoo 17How to Create User Notification in Odoo 17
How to Create User Notification in Odoo 17
Celine George
ย 
Accounting for Restricted Grants When and How To Record Properly
Accounting for Restricted Grants  When and How To Record ProperlyAccounting for Restricted Grants  When and How To Record Properly
Accounting for Restricted Grants When and How To Record Properly
TechSoup
ย 
bryophytes.pptx bsc botany honours second semester
bryophytes.pptx bsc botany honours  second semesterbryophytes.pptx bsc botany honours  second semester
bryophytes.pptx bsc botany honours second semester
Sarojini38
ย 
Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17
Celine George
ย 
The Rise of the Digital Telecommunication Marketplace.pptx
The Rise of the Digital Telecommunication Marketplace.pptxThe Rise of the Digital Telecommunication Marketplace.pptx
The Rise of the Digital Telecommunication Marketplace.pptx
PriyaKumari928991
ย 

Recently uploaded (20)

Keynote given on June 24 for MASSP at Grand Traverse City
Keynote given on June 24 for MASSP at Grand Traverse CityKeynote given on June 24 for MASSP at Grand Traverse City
Keynote given on June 24 for MASSP at Grand Traverse City
ย 
pol sci Election and Representation Class 11 Notes.pdf
pol sci Election and Representation Class 11 Notes.pdfpol sci Election and Representation Class 11 Notes.pdf
pol sci Election and Representation Class 11 Notes.pdf
ย 
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
220711130100 udita Chakraborty  Aims and objectives of national policy on inf...220711130100 udita Chakraborty  Aims and objectives of national policy on inf...
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
ย 
Creating Images and Videos through AI.pptx
Creating Images and Videos through AI.pptxCreating Images and Videos through AI.pptx
Creating Images and Videos through AI.pptx
ย 
A Quiz on Drug Abuse Awareness by Quizzito
A Quiz on Drug Abuse Awareness by QuizzitoA Quiz on Drug Abuse Awareness by Quizzito
A Quiz on Drug Abuse Awareness by Quizzito
ย 
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptxCapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
ย 
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
ย 
Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...
Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...
Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...
ย 
Get Success with the Latest UiPath UIPATH-ADPV1 Exam Dumps (V11.02) 2024
Get Success with the Latest UiPath UIPATH-ADPV1 Exam Dumps (V11.02) 2024Get Success with the Latest UiPath UIPATH-ADPV1 Exam Dumps (V11.02) 2024
Get Success with the Latest UiPath UIPATH-ADPV1 Exam Dumps (V11.02) 2024
ย 
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
220711130083 SUBHASHREE RAKSHIT  Internet resources for social science220711130083 SUBHASHREE RAKSHIT  Internet resources for social science
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
ย 
Information and Communication Technology in Education
Information and Communication Technology in EducationInformation and Communication Technology in Education
Information and Communication Technology in Education
ย 
IoT (Internet of Things) introduction Notes.pdf
IoT (Internet of Things) introduction Notes.pdfIoT (Internet of Things) introduction Notes.pdf
IoT (Internet of Things) introduction Notes.pdf
ย 
Decolonizing Universal Design for Learning
Decolonizing Universal Design for LearningDecolonizing Universal Design for Learning
Decolonizing Universal Design for Learning
ย 
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
ย 
Bแป˜ Bร€I TแบฌP TEST THEO UNIT - FORM 2025 - TIแบพNG ANH 12 GLOBAL SUCCESS - KรŒ 1 (B...
Bแป˜ Bร€I TแบฌP TEST THEO UNIT - FORM 2025 - TIแบพNG ANH 12 GLOBAL SUCCESS - KรŒ 1 (B...Bแป˜ Bร€I TแบฌP TEST THEO UNIT - FORM 2025 - TIแบพNG ANH 12 GLOBAL SUCCESS - KรŒ 1 (B...
Bแป˜ Bร€I TแบฌP TEST THEO UNIT - FORM 2025 - TIแบพNG ANH 12 GLOBAL SUCCESS - KรŒ 1 (B...
ย 
How to Create User Notification in Odoo 17
How to Create User Notification in Odoo 17How to Create User Notification in Odoo 17
How to Create User Notification in Odoo 17
ย 
Accounting for Restricted Grants When and How To Record Properly
Accounting for Restricted Grants  When and How To Record ProperlyAccounting for Restricted Grants  When and How To Record Properly
Accounting for Restricted Grants When and How To Record Properly
ย 
bryophytes.pptx bsc botany honours second semester
bryophytes.pptx bsc botany honours  second semesterbryophytes.pptx bsc botany honours  second semester
bryophytes.pptx bsc botany honours second semester
ย 
Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17
ย 
The Rise of the Digital Telecommunication Marketplace.pptx
The Rise of the Digital Telecommunication Marketplace.pptxThe Rise of the Digital Telecommunication Marketplace.pptx
The Rise of the Digital Telecommunication Marketplace.pptx
ย 

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
  ็ฟป่ฏ‘๏ผš