SlideShare a Scribd company logo
1 of 23
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

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

Advanced Java - UNIT 3.pptx
Advanced Java - UNIT 3.pptxAdvanced Java - UNIT 3.pptx
Advanced Java - UNIT 3.pptx
eyemitra1
 

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
 
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
 
Java Course 4: Exceptions & Collections
Java Course 4: Exceptions & CollectionsJava Course 4: Exceptions & Collections
Java Course 4: Exceptions & Collections
 

Recently uploaded

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Recently uploaded (20)

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 

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