SlideShare a Scribd company logo
OOP / Slide 1
Collection Framework
OOP / Slide 2
Reduces programming effort
>Increases program speed and quality
>Reduce effort to learn and use new APIs
 Is simply an object that groups multiple elements
into a single unit.
 Sometimes called a container
 Collections are used to store, retrieve, manipulate,
and communicate aggregate data
Benefits of Collection Framework
What is a Collection?
OOP / Slide 3
The Collections Hierarchy
OOP / Slide 4
Collection Framework
 ArrayList Class
 LinkedList Class
 HashSet Class
 LinkedHaseSet Class
 TreeSet Class
 Map Interface
 LinkedHashMap Class
 TreeMap Class
 Hashtable Class
 Comparable Interface
 Comparator Interface
 HashMap Class
OOP / Slide 5
Commonly thrown Exceptions in Collection Framework
 UnSupportedOperationException
 occurs if a Collection cannot be modified.
 ClassCastException
 occurs when one object is incompatible with another.
 NullPointerException
 occurs when you try to store null object in Collection.
 IllegalArgumentException
 thrown if an invalid argument is used.
 IllegalStateException
 thrown if you try to add an element to an already full Collection.
OOP / Slide 6
Hierarchy of ArrayList class:
ArrayList<Integer> list = new ArrayList<Integer>(0);
list.add(1001);
list.add(1002);
System.out.println(list.get(5));
Exception:
java.lang.IndexOutOfBoundsException:
Index: 4, Size: 2
IndexOutOfBoundsException
OOP / Slide 7
ArrayList class:
 Uses a dynamic array for storing the elements.It extends
AbstractList class and implements List interface.
 Can contain duplicate elements.
 It Maintains insertion order.
 Not synchronized.
 Random access because array works at the index basis.
 Manipulation slow because a lot of shifting needs to be
occurred.
OOP / Slide 8
Methods of Collection interface
public boolean equals(Object element) : matches two collection.
OOP / Slide 9
Example of addAll(Collection) method:
OOP / Slide 10
Example of removeAll() method:
OOP / Slide 11
Example of retainAll() method:
OOP / Slide 12
By Iterator interface.
package Collection;
import java.util.ArrayList;
import java.util.Iterator;
public class Array1 {
public static void main(String[] args) {
ArrayList alist=new ArrayList();
alist.add("Ravi");
alist.add("Vijay");
alist.add("Ravi");
Iterator itr=alist.iterator();
while(itr.hasNext()){
System.out.println(itr.next());
} }}
Output:
Ravi
Vijay
Ravi
OOP / Slide 13
ArrayList: By for-each loop.
OOP / Slide 14
LinkedList class:
 Uses doubly linked list to store the elements. It extends the
AbstractList class and implements List and Deque
interfaces.
 Can contain duplicate elements.
 Maintains insertion order.
 Not synchronized.
 No random access.
 Manipulation fast because no shifting needs to be occurred.
OOP / Slide 15
Difference between List and Set:
List can contain duplicate elements
whereas
Set contains unique elements only.
OOP / Slide 16
Linked List
OOP / Slide 17
HashSet class:
 Uses hashtable to store the elements.It extends
AbstractSet class and implements Set interface.
 contains unique elements only.
HashSet hs=new HashSet();
hs.add("Ravi");
hs.add("Vijay");
Iterator itr=hs.iterator();
while(itr.hasNext()){
System.out.println(itr.next());
Output:
Ravi
Vijay
OOP / Slide 18
TreeSet class:
1. Contains unique elements
only like HashSet.
2. The TreeSet class
implements NavigableSet
interface that extends the
SortedSet interface.
3. Maintains ascending order.
OOP / Slide 19
Treeset
Output:
Ravi
vijay
OOP / Slide 20
HashMap
 A HashMap contains values based on the key. It implements
the Map interface and extends AbstractMap class.
 It contains only unique elements.
 It may have one null key and multiple null values.
 It maintains no order.
OOP / Slide 21
HashMap class:
Hierarchy of HashMap
 What is difference
between HashSet and
HashMap?
HashSet contains only
values whereas HashMap
contains entry(key and
value).
OOP / Slide 22
HashMap
OOP / Slide 23
Thank You
Guna.dgv.88@gmail.com

More Related Content

What's hot

Collections framework in java
Collections framework in javaCollections framework in java
Collections framework in java
yugandhar vadlamudi
 
Java.util
Java.utilJava.util
Java.util
Ramakrishna kapa
 
Java collections concept
Java collections conceptJava collections concept
Java collections concept
kumar gaurav
 
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
 
JAVA Collections frame work ppt
 JAVA Collections frame work ppt JAVA Collections frame work ppt
JAVA Collections frame work ppt
Ranjith Alappadan
 
Collections Array list
Collections Array listCollections Array list
Collections Array list
RatnaJava
 
Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection framework
ankitgarg_er
 
Collections lecture 35 40
Collections lecture 35 40Collections lecture 35 40
Collections lecture 35 40
bhawna sharma
 
C# Collection classes
C# Collection classesC# Collection classes
C# Collection classes
MohitKumar1985
 
The list interface (the java™ tutorials collections interfaces)
The list interface (the java™ tutorials   collections   interfaces)The list interface (the java™ tutorials   collections   interfaces)
The list interface (the java™ tutorials collections interfaces)
charan kumar
 
Functional programming
Functional programmingFunctional programming
Functional programming
Lhouceine OUHAMZA
 
Report cs3 pillos
Report cs3 pillosReport cs3 pillos
Report cs3 pillos
paul gonzaga
 

What's hot (12)

Collections framework in java
Collections framework in javaCollections framework in java
Collections framework in java
 
Java.util
Java.utilJava.util
Java.util
 
Java collections concept
Java collections conceptJava collections concept
Java collections concept
 
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)
 
JAVA Collections frame work ppt
 JAVA Collections frame work ppt JAVA Collections frame work ppt
JAVA Collections frame work ppt
 
Collections Array list
Collections Array listCollections Array list
Collections Array list
 
Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection framework
 
Collections lecture 35 40
Collections lecture 35 40Collections lecture 35 40
Collections lecture 35 40
 
C# Collection classes
C# Collection classesC# Collection classes
C# Collection classes
 
The list interface (the java™ tutorials collections interfaces)
The list interface (the java™ tutorials   collections   interfaces)The list interface (the java™ tutorials   collections   interfaces)
The list interface (the java™ tutorials collections interfaces)
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
Report cs3 pillos
Report cs3 pillosReport cs3 pillos
Report cs3 pillos
 

Viewers also liked

04 Compasión por los imperdonables
04 Compasión por los imperdonables04 Compasión por los imperdonables
04 Compasión por los imperdonables
Lu Esqueche
 
03 Compasión frente a la muerte
03 Compasión frente a la muerte03 Compasión frente a la muerte
03 Compasión frente a la muerte
Lu Esqueche
 
Evaluation q1 part 2
Evaluation q1 part 2Evaluation q1 part 2
Evaluation q1 part 2ashleymason
 
Presentation part 1 c
Presentation part 1 cPresentation part 1 c
Presentation part 1 cashleymason
 
Patriarcas y Profetas
Patriarcas y ProfetasPatriarcas y Profetas
Patriarcas y Profetas
Lu Esqueche
 
2 como organizar la visitación - IPD
2 como organizar la visitación - IPD2 como organizar la visitación - IPD
2 como organizar la visitación - IPD
Lu Esqueche
 
Sermones #MisionCaleb 2016
Sermones #MisionCaleb 2016Sermones #MisionCaleb 2016
Sermones #MisionCaleb 2016
Lu Esqueche
 
Contents screenshots
Contents screenshotsContents screenshots
Contents screenshotsashleymason
 
Sermon #10diasdeOracion - Verdadera adoracion
Sermon #10diasdeOracion - Verdadera adoracionSermon #10diasdeOracion - Verdadera adoracion
Sermon #10diasdeOracion - Verdadera adoracion
Lu Esqueche
 

Viewers also liked (17)

04 Compasión por los imperdonables
04 Compasión por los imperdonables04 Compasión por los imperdonables
04 Compasión por los imperdonables
 
03 Compasión frente a la muerte
03 Compasión frente a la muerte03 Compasión frente a la muerte
03 Compasión frente a la muerte
 
Evaluation q1
Evaluation q1Evaluation q1
Evaluation q1
 
Lego part 4
Lego part 4Lego part 4
Lego part 4
 
Evaluation q1 part 2
Evaluation q1 part 2Evaluation q1 part 2
Evaluation q1 part 2
 
Lego part 2
Lego part 2Lego part 2
Lego part 2
 
Evaluation q3
Evaluation q3Evaluation q3
Evaluation q3
 
Evaluation Q4
Evaluation Q4Evaluation Q4
Evaluation Q4
 
Lego part 3
Lego part 3Lego part 3
Lego part 3
 
Inner class
Inner classInner class
Inner class
 
WFA Presentation
WFA PresentationWFA Presentation
WFA Presentation
 
Presentation part 1 c
Presentation part 1 cPresentation part 1 c
Presentation part 1 c
 
Patriarcas y Profetas
Patriarcas y ProfetasPatriarcas y Profetas
Patriarcas y Profetas
 
2 como organizar la visitación - IPD
2 como organizar la visitación - IPD2 como organizar la visitación - IPD
2 como organizar la visitación - IPD
 
Sermones #MisionCaleb 2016
Sermones #MisionCaleb 2016Sermones #MisionCaleb 2016
Sermones #MisionCaleb 2016
 
Contents screenshots
Contents screenshotsContents screenshots
Contents screenshots
 
Sermon #10diasdeOracion - Verdadera adoracion
Sermon #10diasdeOracion - Verdadera adoracionSermon #10diasdeOracion - Verdadera adoracion
Sermon #10diasdeOracion - Verdadera adoracion
 

Similar to Collection

collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptx
SoniaKapoor56
 
Collections in Java Notes
Collections in Java NotesCollections in Java Notes
Collections in Java Notes
Shalabh Chaudhary
 
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
 
Collection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshanCollection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshan
Zeeshan Khan
 
Collections - Lists & sets
Collections - Lists & setsCollections - Lists & sets
Collections - Lists & sets
RatnaJava
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
talha ijaz
 
ArrayList.docx
ArrayList.docxArrayList.docx
ArrayList.docx
veerendranath12
 
Advanced Java - UNIT 3.pptx
Advanced Java - UNIT 3.pptxAdvanced Java - UNIT 3.pptx
Advanced Java - UNIT 3.pptx
eyemitra1
 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
Prof. Erwin Globio
 
Nature Activities Binder _ by Slidesgo.pptx
Nature Activities Binder _ by Slidesgo.pptxNature Activities Binder _ by Slidesgo.pptx
Nature Activities Binder _ by Slidesgo.pptx
IllllBikkySharmaIlll
 
Java Collections
Java  Collections Java  Collections
Java Unit 2 (Part 2)
Java Unit 2 (Part 2)Java Unit 2 (Part 2)
Java Unit 2 (Part 2)
SURBHI SAROHA
 
Collections and generic class
Collections and generic classCollections and generic class
Collections and generic class
ifis
 
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
 
Collection framework
Collection frameworkCollection framework
Collection framework
BindhuBhargaviTalasi
 
Lecture 24
Lecture 24Lecture 24
Lecture 24
Debasish Pratihari
 
Java Unit 2(part 3)
Java Unit 2(part 3)Java Unit 2(part 3)
Java Unit 2(part 3)
SURBHI SAROHA
 
Collections Java e Google Collections
Collections Java e Google CollectionsCollections Java e Google Collections
Collections Java e Google Collections
André Faria Gomes
 

Similar to Collection (20)

collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptx
 
Collections in Java Notes
Collections in Java NotesCollections in Java Notes
Collections in Java Notes
 
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
 
Collection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshanCollection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshan
 
Collections - Lists & sets
Collections - Lists & setsCollections - Lists & sets
Collections - Lists & sets
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 
ArrayList.docx
ArrayList.docxArrayList.docx
ArrayList.docx
 
Advanced Java - UNIT 3.pptx
Advanced Java - UNIT 3.pptxAdvanced Java - UNIT 3.pptx
Advanced Java - UNIT 3.pptx
 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
 
Nature Activities Binder _ by Slidesgo.pptx
Nature Activities Binder _ by Slidesgo.pptxNature Activities Binder _ by Slidesgo.pptx
Nature Activities Binder _ by Slidesgo.pptx
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
Java Unit 2 (Part 2)
Java Unit 2 (Part 2)Java Unit 2 (Part 2)
Java Unit 2 (Part 2)
 
Collections and generic class
Collections and generic classCollections and generic class
Collections and generic class
 
Array list (java platform se 8 )
Array list (java platform se 8 )Array list (java platform se 8 )
Array list (java platform se 8 )
 
Collection framework
Collection frameworkCollection framework
Collection framework
 
Lecture 24
Lecture 24Lecture 24
Lecture 24
 
Java Unit 2(part 3)
Java Unit 2(part 3)Java Unit 2(part 3)
Java Unit 2(part 3)
 
Collections
CollectionsCollections
Collections
 
Collections Java e Google Collections
Collections Java e Google CollectionsCollections Java e Google Collections
Collections Java e Google Collections
 

Recently uploaded

Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 

Recently uploaded (20)

Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 

Collection

  • 1. OOP / Slide 1 Collection Framework
  • 2. OOP / Slide 2 Reduces programming effort >Increases program speed and quality >Reduce effort to learn and use new APIs  Is simply an object that groups multiple elements into a single unit.  Sometimes called a container  Collections are used to store, retrieve, manipulate, and communicate aggregate data Benefits of Collection Framework What is a Collection?
  • 3. OOP / Slide 3 The Collections Hierarchy
  • 4. OOP / Slide 4 Collection Framework  ArrayList Class  LinkedList Class  HashSet Class  LinkedHaseSet Class  TreeSet Class  Map Interface  LinkedHashMap Class  TreeMap Class  Hashtable Class  Comparable Interface  Comparator Interface  HashMap Class
  • 5. OOP / Slide 5 Commonly thrown Exceptions in Collection Framework  UnSupportedOperationException  occurs if a Collection cannot be modified.  ClassCastException  occurs when one object is incompatible with another.  NullPointerException  occurs when you try to store null object in Collection.  IllegalArgumentException  thrown if an invalid argument is used.  IllegalStateException  thrown if you try to add an element to an already full Collection.
  • 6. OOP / Slide 6 Hierarchy of ArrayList class: ArrayList<Integer> list = new ArrayList<Integer>(0); list.add(1001); list.add(1002); System.out.println(list.get(5)); Exception: java.lang.IndexOutOfBoundsException: Index: 4, Size: 2 IndexOutOfBoundsException
  • 7. OOP / Slide 7 ArrayList class:  Uses a dynamic array for storing the elements.It extends AbstractList class and implements List interface.  Can contain duplicate elements.  It Maintains insertion order.  Not synchronized.  Random access because array works at the index basis.  Manipulation slow because a lot of shifting needs to be occurred.
  • 8. OOP / Slide 8 Methods of Collection interface public boolean equals(Object element) : matches two collection.
  • 9. OOP / Slide 9 Example of addAll(Collection) method:
  • 10. OOP / Slide 10 Example of removeAll() method:
  • 11. OOP / Slide 11 Example of retainAll() method:
  • 12. OOP / Slide 12 By Iterator interface. package Collection; import java.util.ArrayList; import java.util.Iterator; public class Array1 { public static void main(String[] args) { ArrayList alist=new ArrayList(); alist.add("Ravi"); alist.add("Vijay"); alist.add("Ravi"); Iterator itr=alist.iterator(); while(itr.hasNext()){ System.out.println(itr.next()); } }} Output: Ravi Vijay Ravi
  • 13. OOP / Slide 13 ArrayList: By for-each loop.
  • 14. OOP / Slide 14 LinkedList class:  Uses doubly linked list to store the elements. It extends the AbstractList class and implements List and Deque interfaces.  Can contain duplicate elements.  Maintains insertion order.  Not synchronized.  No random access.  Manipulation fast because no shifting needs to be occurred.
  • 15. OOP / Slide 15 Difference between List and Set: List can contain duplicate elements whereas Set contains unique elements only.
  • 16. OOP / Slide 16 Linked List
  • 17. OOP / Slide 17 HashSet class:  Uses hashtable to store the elements.It extends AbstractSet class and implements Set interface.  contains unique elements only. HashSet hs=new HashSet(); hs.add("Ravi"); hs.add("Vijay"); Iterator itr=hs.iterator(); while(itr.hasNext()){ System.out.println(itr.next()); Output: Ravi Vijay
  • 18. OOP / Slide 18 TreeSet class: 1. Contains unique elements only like HashSet. 2. The TreeSet class implements NavigableSet interface that extends the SortedSet interface. 3. Maintains ascending order.
  • 19. OOP / Slide 19 Treeset Output: Ravi vijay
  • 20. OOP / Slide 20 HashMap  A HashMap contains values based on the key. It implements the Map interface and extends AbstractMap class.  It contains only unique elements.  It may have one null key and multiple null values.  It maintains no order.
  • 21. OOP / Slide 21 HashMap class: Hierarchy of HashMap  What is difference between HashSet and HashMap? HashSet contains only values whereas HashMap contains entry(key and value).
  • 22. OOP / Slide 22 HashMap
  • 23. OOP / Slide 23 Thank You Guna.dgv.88@gmail.com