SlideShare a Scribd company logo
COLLECTION
FRAMEWORK
www.blog.cpd-india.com
Call Us: 011-65164822
CPD TECHNOLOGIES
Add:- Block C 9/8, Sector -7, Rohini , Delhi-110085, India
www.cpd-india.com
COLLECTION
FRAMEWORK
The collections framework is a unified architecture for
representing and manipulating collections, enabling
them to be manipulated independently of the details
of their representation. It reduces programming effort
while increasing performance. It enables
interoperability among unrelated APIs, reduces effort
in designing and learning new APIs, and fosters
software reuse. The framework is based on more than
a dozen collection interfaces. It includes
implementations of these interfaces and algorithms to
manipulate them.
CONTENTS
 What is Collection?
 Collections Framework
 Collections Hierarchy
 Collections Implementations
Set
List
Map
OBJECTIVES
 Define a collection
 Describe the collections framework
 Describe the collections hierarchy
 Demonstrate each collection implementation
WHAT IS A COLLECTION?
 A Collection (also known as container) is an object that contains a
group of objects treated as a single unit.
 Any type of objects can be stored, retrieved and manipulated as
elements of collections.
COLLECTIONS FRAMEWORK
Collections Framework is a unified architecture for
managing collections
Main Parts of Collections Framework
1. Interfaces
 Core interfaces defining common functionality exhibited by
collections
1. Implementations
 Concrete classes of the core interfaces providing data structures
1. Operations
 Methods that perform various operations on collections
COLLECTIONS FRAMEWORK
INTERFACES
Core Interface Description
Collection specifies contract that all collections should implement
Set defines functionality for a set of unique elements
SortedSet defines functionality for a set where elements are sorted
List defines functionality for an ordered list of non- unique elements
Map defines functionality for mapping of unique keys to values
SortedMap defines functionality for a map where its keys are sorted
COLLECTIONS FRAMEWORK
IMPLEMENTATIONS
Set List Map
HashSet ArrayList HashMap
LinkedHashSet LinkedList LinkedHashMap
TreeSet Vector Hashtable
Tree Map
Note: Hashtable uses a lower-case “t”
OPERATIONS
Basic collection operations:
 Check if collection is empty
 Check if an object exists in collection.
 Retrieve an object from collection
 Add object to collection
 Remove object from collection
 Iterate collection and inspect each object
Each operation has a corresponding method implementation for
each collection type
COLLECTIONS
CHARACTERISTICS
 Ordered
Elements are stored and accessed in a specific
order
 Sorted
Elements are stored and accessed in a sorted
order
 Indexed
Elements can be accessed using an index
 Unique
Collection does not allow duplicates
ITERATOR
 An iterator is an object used to mark a position in a
collection of data and to move from item to item within
the collection
Syntax:
Iterator <variable> = <CollectionObject>.iterator();
COLLECTIONS HIERARCHY
SET AND LIST
HashSet
Collection
SortedSet
ListSet
LinkedHashSet TreeSet LinkedList Vector ArrayList
implements
implements
implements
implements extends
extends
COLLECTIONS HIERARCHY
MAP
Map
SortedMap
Hashtable
LinkedHashMap
HashMap TreeMap
implements
implements
extends
extends
COLLECTION IMPLEMENTATIONS
Set : Unique things (classes that implement Set)
Map : Things with a unique ID (classes that implement Map)
List : Lists of things (classes that implement List)
LIST
A List cares about the index.
“Paul”“Paul” “Mark”“Mark” “John”“John” “Paul”“Paul” “Luke”“Luke”value
index 0 1 2 3 4
LinkedListLinkedListVectorVectorArrayListArrayList
LIST IMPLEMENTATIONS
ARRAY LIST
import java.util.ArrayList;
public class MyArrayList {
public static void main(String args[ ]) {
ArrayList alist = new ArrayList( );
alist.add(new String("One"));
alist.add(new String("Two"));
alist.add(new String("Three"));
System.out.println(alist.get(0));
System.out.println(alist.get(1));
System.out.println(alist.get(2));
}
}
One
Two
Three
LIST IMPLEMENTATIONS
VECTOR
import java.util.Vector;
public class MyVector {
public static void main(String args[ ]) {
Vector vecky = new Vector( );
vecky.add(new Integer(1));
vecky.add(new Integer(2));
vecky.add(new Integer(3));
for(int x=0; x<3; x++) {
System.out.println(vecky.get(x));
}
}
}
1
2
3
LIST IMPLEMENTATIONS
LINKED LIST
import java.util.LinkedList;
public class MyLinkedList {
public static void main(String args[ ]) {
LinkedList link = new LinkedList( );
link.add(new Double(2.0));
link.addLast(new Double(3.0));
link.addFirst(new Double(1.0));
Object array[ ] = link.toArray( );
for(int x=0; x<3; x++) {
System.out.println(array[x]);
}
}
}
1.0
2.0
3.0
SET
A Set cares about uniqueness, it doesn’t allow duplicates.
“Paul”“Paul”
“Mark”“Mark”
“John”“John”
“Luke”“Luke”
“Fred”“Fred”
“Peter”“Peter”
TreeSetTreeSetLinkedHashSetLinkedHashSetHashSetHashSet
SET IMPLEMENTATIONS
HASH SET
import java.util.*;
public class MyHashSet {
public static void main(String args[ ]) {
HashSet hash = new HashSet( );
hash.add("a");
hash.add("b");
hash.add("c");
hash.add("d");
Iterator iterator = hash.iterator( );
while(iterator.hasNext( )) {
System.out.println(iterator.next( ));
}
}
}
d
a
c
b
SET IMPLEMENTATIONS
LINKED HASH SET
import java.util.LinkedHashSet;
public class MyLinkedHashSet {
public static void main(String args[ ]) {
LinkedHashSet lhs = new LinkedHashSet();
lhs.add(new String("One"));
lhs.add(new String("Two"));
lhs.add(new String("Three"));
Object array[] = lhs.toArray( );
for(int x=0; x<3; x++) {
System.out.println(array[x]);
}
}
}
One
Two
Three
SET IMPLEMENTATIONS
TREE SET
import java.util.TreeSet;
import java.util.Iterator;
public class MyTreeSet {
public static void main(String args[ ]) {
TreeSet tree = new TreeSet();
tree.add("Jody");
tree.add("Remiel");
tree.add("Reggie");
tree.add("Philippe");
Iterator iterator = tree.iterator( );
while(iterator.hasNext( )) {
System.out.println(iterator.next( ).toString( ));
}
}
}
Jody
Philippe
Reggie
Remiel
MAP
A Map cares about unique identifiers.
“Paul”“Paul” “Mark”“Mark” “John”“John” “Paul”“Paul” “Luke”“Luke”
key
value
“Pl” “Ma” “Jn” “ul” “Le”
LinkedHashMapLinkedHashMap TreeMapTreeMapHashtableHashtableHashMapHashMap
MAP IMPLEMENTATIONS
HASH MAP
import java.util.HashMap;
public class MyHashMap {
public static void main(String args[ ]) {
HashMap map = new HashMap( );
map.put("name", "Jody");
map.put("id", new Integer(446));
map.put("address", "Manila");
System.out.println("Name: " + map.get("name"));
System.out.println("ID: " + map.get("id"));
System.out.println("Address: " + map.get("address"));
}
}
Name: Jody
ID: 446
Address: Manila
MAP IMPLEMENTATIONS
HASH TABLE
import java.util.Hashtable;
public class MyHashtable {
public static void main(String args[ ]) {
Hashtable table = new Hashtable( );
table.put("name", "Jody");
table.put("id", new Integer(1001));
table.put("address", new String("Manila"));
System.out.println("Table of Contents:" + table);
}
}
Table of Contents:
{address=Manila, name=Jody, id=1001}
MAP IMPLEMENTATIONS
LINKED HASH MAP
import java.util.*;
public class MyLinkedHashMap {
public static void main(String args[ ]) {
int iNum = 0;
LinkedHashMap myMap = new LinkedHashMap( );
myMap.put("name", "Jody");
myMap.put("id", new Integer(446));
myMap.put("address", "Manila");
myMap.put("type", "Savings");
Collection values = myMap.values( );
Iterator iterator = values.iterator( );
while(iterator.hasNext()) {
System.out.println(iterator.next( ));
}
}
}
Jody
446
Manila
Savings
MAP IMPLEMENTATIONS
TREE MAPimport java.util.*;
public class MyTreeMap {
public static void main(String args[]) {
TreeMap treeMap = new TreeMap( );
treeMap.put("name", "Jody");
treeMap.put("id", new Integer(446));
treeMap.put("address", "Manila");
Collection values = treeMap.values()
Iterator iterator = values.iterator( );
System.out.println("Printing the VALUES....");
while (iterator.hasNext()) {
System.out.println(iterator.next( ));
}
}
}
Printing the VALUES....
Manila
446
Jody
COLLECTION CLASSES SUMMARY
NoBy indexXLinkedList
NoBy indexXVector
NoBy indexXArrayList
NoBy insertion order or
last access order
XLinkedHashSet
By natural order or
custom comparison rules
SortedXTreeSet
NoNoXHashSet
NoBy insertion order or
last access order
XLinkedHashMap
By natural order or
custom comparison rules
SortedXTreeMap
NoNoXHashtable
NoNoXHashMap
SortedOrderedListSetMapClass
KEY POINTS
 Collections Framework contains:
1. Interfaces
2. Implementations
3. Operations
 A list cares about the index.
 A set cares about uniqueness, it does not allow
duplicates.
 A map cares about unique identifiers.
THANK YOU
CPD TECHNOLOGIES
Block C 9/8, Sector -7, Rohini, Delhi-110085, India
Landmark: Near Rohini East Metro Station, Opposite
Metro Pillar No-397
Telephone: 011-65164822
Mobile: +91- 8860352748
Email: support@cpd-india.com
Ad

More Related Content

What's hot (20)

5 collection framework
5 collection framework5 collection framework
5 collection framework
Minal Maniar
 
Java Collections
Java  Collections Java  Collections
Java Collections
Kongu Engineering College, Perundurai, Erode
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
Tanmoy Barman
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
RahulAnanda1
 
JVM
JVMJVM
JVM
baabtra.com - No. 1 supplier of quality freshers
 
Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection framework
ankitgarg_er
 
Java swing
Java swingJava swing
Java swing
Apurbo Datta
 
Generics
GenericsGenerics
Generics
Ravi_Kant_Sahu
 
Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
 
I/O Streams
I/O StreamsI/O Streams
I/O Streams
Ravi Chythanya
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
Aneega
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets
Hitesh-Java
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
OpenSource Technologies Pvt. Ltd.
 
Wrapper classes
Wrapper classes Wrapper classes
Wrapper classes
Kongu Engineering College, Perundurai, Erode
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
Abhilash Nair
 
Java string handling
Java string handlingJava string handling
Java string handling
Salman Khan
 
Swing and AWT in java
Swing and AWT in javaSwing and AWT in java
Swing and AWT in java
Adil Mehmoood
 
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 collection
Java collectionJava collection
Java collection
Arati Gadgil
 

Similar to Collection Framework in java (20)

collection framework in java
collection framework in javacollection framework in java
collection framework in java
MANOJ KUMAR
 
javaprograming-COLLECTION FRAMEWORK-171012084019.pptx
javaprograming-COLLECTION FRAMEWORK-171012084019.pptxjavaprograming-COLLECTION FRAMEWORK-171012084019.pptx
javaprograming-COLLECTION FRAMEWORK-171012084019.pptx
aniketkumar02062003
 
collectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptxcollectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptx
hemanth248901
 
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
collectionscollections
collections
javeed_mhd
 
Lecture 24
Lecture 24Lecture 24
Lecture 24
Debasish Pratihari
 
M251_Meeting 8 (SetsandMap Advanced Java).ppt
M251_Meeting 8 (SetsandMap Advanced Java).pptM251_Meeting 8 (SetsandMap Advanced Java).ppt
M251_Meeting 8 (SetsandMap Advanced Java).ppt
smartashammari
 
M251_Meeting 8 (Sets and Maps_Java_).ppt
M251_Meeting 8 (Sets and Maps_Java_).pptM251_Meeting 8 (Sets and Maps_Java_).ppt
M251_Meeting 8 (Sets and Maps_Java_).ppt
smartashammari
 
Collections
CollectionsCollections
Collections
Manav Prasad
 
oop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionoop lecture framework,list,maps,collection
oop lecture framework,list,maps,collection
ssuseredfbe9
 
07 java collection
07 java collection07 java collection
07 java collection
Abhishek Khune
 
Collections generic
Collections genericCollections generic
Collections generic
sandhish
 
Collections in Java
Collections in JavaCollections in Java
Collections in Java
Khasim Cise
 
Collections
CollectionsCollections
Collections
Rajkattamuri
 
Collection framework
Collection frameworkCollection framework
Collection framework
DilvarSingh2
 
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
 
collectionsframework210616084411 (1).pptx
collectionsframework210616084411 (1).pptxcollectionsframework210616084411 (1).pptx
collectionsframework210616084411 (1).pptx
ArunPatrick2
 
Java Collection Framework 2nd year B.Tech.pptx
Java Collection Framework 2nd year B.Tech.pptxJava Collection Framework 2nd year B.Tech.pptx
Java Collection Framework 2nd year B.Tech.pptx
kmd198809
 
ArrayList.docx
ArrayList.docxArrayList.docx
ArrayList.docx
veerendranath12
 
Collections
CollectionsCollections
Collections
Gujarat Technological University
 
collection framework in java
collection framework in javacollection framework in java
collection framework in java
MANOJ KUMAR
 
javaprograming-COLLECTION FRAMEWORK-171012084019.pptx
javaprograming-COLLECTION FRAMEWORK-171012084019.pptxjavaprograming-COLLECTION FRAMEWORK-171012084019.pptx
javaprograming-COLLECTION FRAMEWORK-171012084019.pptx
aniketkumar02062003
 
collectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptxcollectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptx
hemanth248901
 
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
 
M251_Meeting 8 (SetsandMap Advanced Java).ppt
M251_Meeting 8 (SetsandMap Advanced Java).pptM251_Meeting 8 (SetsandMap Advanced Java).ppt
M251_Meeting 8 (SetsandMap Advanced Java).ppt
smartashammari
 
M251_Meeting 8 (Sets and Maps_Java_).ppt
M251_Meeting 8 (Sets and Maps_Java_).pptM251_Meeting 8 (Sets and Maps_Java_).ppt
M251_Meeting 8 (Sets and Maps_Java_).ppt
smartashammari
 
oop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionoop lecture framework,list,maps,collection
oop lecture framework,list,maps,collection
ssuseredfbe9
 
Collections generic
Collections genericCollections generic
Collections generic
sandhish
 
Collections in Java
Collections in JavaCollections in Java
Collections in Java
Khasim Cise
 
Collection framework
Collection frameworkCollection framework
Collection framework
DilvarSingh2
 
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
 
collectionsframework210616084411 (1).pptx
collectionsframework210616084411 (1).pptxcollectionsframework210616084411 (1).pptx
collectionsframework210616084411 (1).pptx
ArunPatrick2
 
Java Collection Framework 2nd year B.Tech.pptx
Java Collection Framework 2nd year B.Tech.pptxJava Collection Framework 2nd year B.Tech.pptx
Java Collection Framework 2nd year B.Tech.pptx
kmd198809
 
Ad

Recently uploaded (20)

Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
TechSoup
 
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
Dr. Nasir Mustafa
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdfRanking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Rafael Villas B
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
Tax evasion, Tax planning & Tax avoidance.pptx
Tax evasion, Tax  planning &  Tax avoidance.pptxTax evasion, Tax  planning &  Tax avoidance.pptx
Tax evasion, Tax planning & Tax avoidance.pptx
manishbaidya2017
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE  BY sweety Tamanna Mahapatra MSc PediatricAPGAR SCORE  BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
SweetytamannaMohapat
 
Lecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptx
Lecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptxLecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptx
Lecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptx
Arshad Shaikh
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
How to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo SlidesHow to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo Slides
Celine George
 
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
TechSoup
 
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
Dr. Nasir Mustafa
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdfRanking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Rafael Villas B
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
Tax evasion, Tax planning & Tax avoidance.pptx
Tax evasion, Tax  planning &  Tax avoidance.pptxTax evasion, Tax  planning &  Tax avoidance.pptx
Tax evasion, Tax planning & Tax avoidance.pptx
manishbaidya2017
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE  BY sweety Tamanna Mahapatra MSc PediatricAPGAR SCORE  BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
SweetytamannaMohapat
 
Lecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptx
Lecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptxLecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptx
Lecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptx
Arshad Shaikh
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
How to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo SlidesHow to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo Slides
Celine George
 
Ad

Collection Framework in java

  • 1. COLLECTION FRAMEWORK www.blog.cpd-india.com Call Us: 011-65164822 CPD TECHNOLOGIES Add:- Block C 9/8, Sector -7, Rohini , Delhi-110085, India www.cpd-india.com
  • 2. COLLECTION FRAMEWORK The collections framework is a unified architecture for representing and manipulating collections, enabling them to be manipulated independently of the details of their representation. It reduces programming effort while increasing performance. It enables interoperability among unrelated APIs, reduces effort in designing and learning new APIs, and fosters software reuse. The framework is based on more than a dozen collection interfaces. It includes implementations of these interfaces and algorithms to manipulate them.
  • 3. CONTENTS  What is Collection?  Collections Framework  Collections Hierarchy  Collections Implementations Set List Map
  • 4. OBJECTIVES  Define a collection  Describe the collections framework  Describe the collections hierarchy  Demonstrate each collection implementation
  • 5. WHAT IS A COLLECTION?  A Collection (also known as container) is an object that contains a group of objects treated as a single unit.  Any type of objects can be stored, retrieved and manipulated as elements of collections.
  • 6. COLLECTIONS FRAMEWORK Collections Framework is a unified architecture for managing collections Main Parts of Collections Framework 1. Interfaces  Core interfaces defining common functionality exhibited by collections 1. Implementations  Concrete classes of the core interfaces providing data structures 1. Operations  Methods that perform various operations on collections
  • 7. COLLECTIONS FRAMEWORK INTERFACES Core Interface Description Collection specifies contract that all collections should implement Set defines functionality for a set of unique elements SortedSet defines functionality for a set where elements are sorted List defines functionality for an ordered list of non- unique elements Map defines functionality for mapping of unique keys to values SortedMap defines functionality for a map where its keys are sorted
  • 8. COLLECTIONS FRAMEWORK IMPLEMENTATIONS Set List Map HashSet ArrayList HashMap LinkedHashSet LinkedList LinkedHashMap TreeSet Vector Hashtable Tree Map Note: Hashtable uses a lower-case “t”
  • 9. OPERATIONS Basic collection operations:  Check if collection is empty  Check if an object exists in collection.  Retrieve an object from collection  Add object to collection  Remove object from collection  Iterate collection and inspect each object Each operation has a corresponding method implementation for each collection type
  • 10. COLLECTIONS CHARACTERISTICS  Ordered Elements are stored and accessed in a specific order  Sorted Elements are stored and accessed in a sorted order  Indexed Elements can be accessed using an index  Unique Collection does not allow duplicates
  • 11. ITERATOR  An iterator is an object used to mark a position in a collection of data and to move from item to item within the collection Syntax: Iterator <variable> = <CollectionObject>.iterator();
  • 12. COLLECTIONS HIERARCHY SET AND LIST HashSet Collection SortedSet ListSet LinkedHashSet TreeSet LinkedList Vector ArrayList implements implements implements implements extends extends
  • 14. COLLECTION IMPLEMENTATIONS Set : Unique things (classes that implement Set) Map : Things with a unique ID (classes that implement Map) List : Lists of things (classes that implement List)
  • 15. LIST A List cares about the index. “Paul”“Paul” “Mark”“Mark” “John”“John” “Paul”“Paul” “Luke”“Luke”value index 0 1 2 3 4 LinkedListLinkedListVectorVectorArrayListArrayList
  • 16. LIST IMPLEMENTATIONS ARRAY LIST import java.util.ArrayList; public class MyArrayList { public static void main(String args[ ]) { ArrayList alist = new ArrayList( ); alist.add(new String("One")); alist.add(new String("Two")); alist.add(new String("Three")); System.out.println(alist.get(0)); System.out.println(alist.get(1)); System.out.println(alist.get(2)); } } One Two Three
  • 17. LIST IMPLEMENTATIONS VECTOR import java.util.Vector; public class MyVector { public static void main(String args[ ]) { Vector vecky = new Vector( ); vecky.add(new Integer(1)); vecky.add(new Integer(2)); vecky.add(new Integer(3)); for(int x=0; x<3; x++) { System.out.println(vecky.get(x)); } } } 1 2 3
  • 18. LIST IMPLEMENTATIONS LINKED LIST import java.util.LinkedList; public class MyLinkedList { public static void main(String args[ ]) { LinkedList link = new LinkedList( ); link.add(new Double(2.0)); link.addLast(new Double(3.0)); link.addFirst(new Double(1.0)); Object array[ ] = link.toArray( ); for(int x=0; x<3; x++) { System.out.println(array[x]); } } } 1.0 2.0 3.0
  • 19. SET A Set cares about uniqueness, it doesn’t allow duplicates. “Paul”“Paul” “Mark”“Mark” “John”“John” “Luke”“Luke” “Fred”“Fred” “Peter”“Peter” TreeSetTreeSetLinkedHashSetLinkedHashSetHashSetHashSet
  • 20. SET IMPLEMENTATIONS HASH SET import java.util.*; public class MyHashSet { public static void main(String args[ ]) { HashSet hash = new HashSet( ); hash.add("a"); hash.add("b"); hash.add("c"); hash.add("d"); Iterator iterator = hash.iterator( ); while(iterator.hasNext( )) { System.out.println(iterator.next( )); } } } d a c b
  • 21. SET IMPLEMENTATIONS LINKED HASH SET import java.util.LinkedHashSet; public class MyLinkedHashSet { public static void main(String args[ ]) { LinkedHashSet lhs = new LinkedHashSet(); lhs.add(new String("One")); lhs.add(new String("Two")); lhs.add(new String("Three")); Object array[] = lhs.toArray( ); for(int x=0; x<3; x++) { System.out.println(array[x]); } } } One Two Three
  • 22. SET IMPLEMENTATIONS TREE SET import java.util.TreeSet; import java.util.Iterator; public class MyTreeSet { public static void main(String args[ ]) { TreeSet tree = new TreeSet(); tree.add("Jody"); tree.add("Remiel"); tree.add("Reggie"); tree.add("Philippe"); Iterator iterator = tree.iterator( ); while(iterator.hasNext( )) { System.out.println(iterator.next( ).toString( )); } } } Jody Philippe Reggie Remiel
  • 23. MAP A Map cares about unique identifiers. “Paul”“Paul” “Mark”“Mark” “John”“John” “Paul”“Paul” “Luke”“Luke” key value “Pl” “Ma” “Jn” “ul” “Le” LinkedHashMapLinkedHashMap TreeMapTreeMapHashtableHashtableHashMapHashMap
  • 24. MAP IMPLEMENTATIONS HASH MAP import java.util.HashMap; public class MyHashMap { public static void main(String args[ ]) { HashMap map = new HashMap( ); map.put("name", "Jody"); map.put("id", new Integer(446)); map.put("address", "Manila"); System.out.println("Name: " + map.get("name")); System.out.println("ID: " + map.get("id")); System.out.println("Address: " + map.get("address")); } } Name: Jody ID: 446 Address: Manila
  • 25. MAP IMPLEMENTATIONS HASH TABLE import java.util.Hashtable; public class MyHashtable { public static void main(String args[ ]) { Hashtable table = new Hashtable( ); table.put("name", "Jody"); table.put("id", new Integer(1001)); table.put("address", new String("Manila")); System.out.println("Table of Contents:" + table); } } Table of Contents: {address=Manila, name=Jody, id=1001}
  • 26. MAP IMPLEMENTATIONS LINKED HASH MAP import java.util.*; public class MyLinkedHashMap { public static void main(String args[ ]) { int iNum = 0; LinkedHashMap myMap = new LinkedHashMap( ); myMap.put("name", "Jody"); myMap.put("id", new Integer(446)); myMap.put("address", "Manila"); myMap.put("type", "Savings"); Collection values = myMap.values( ); Iterator iterator = values.iterator( ); while(iterator.hasNext()) { System.out.println(iterator.next( )); } } } Jody 446 Manila Savings
  • 27. MAP IMPLEMENTATIONS TREE MAPimport java.util.*; public class MyTreeMap { public static void main(String args[]) { TreeMap treeMap = new TreeMap( ); treeMap.put("name", "Jody"); treeMap.put("id", new Integer(446)); treeMap.put("address", "Manila"); Collection values = treeMap.values() Iterator iterator = values.iterator( ); System.out.println("Printing the VALUES...."); while (iterator.hasNext()) { System.out.println(iterator.next( )); } } } Printing the VALUES.... Manila 446 Jody
  • 28. COLLECTION CLASSES SUMMARY NoBy indexXLinkedList NoBy indexXVector NoBy indexXArrayList NoBy insertion order or last access order XLinkedHashSet By natural order or custom comparison rules SortedXTreeSet NoNoXHashSet NoBy insertion order or last access order XLinkedHashMap By natural order or custom comparison rules SortedXTreeMap NoNoXHashtable NoNoXHashMap SortedOrderedListSetMapClass
  • 29. KEY POINTS  Collections Framework contains: 1. Interfaces 2. Implementations 3. Operations  A list cares about the index.  A set cares about uniqueness, it does not allow duplicates.  A map cares about unique identifiers.
  • 30. THANK YOU CPD TECHNOLOGIES Block C 9/8, Sector -7, Rohini, Delhi-110085, India Landmark: Near Rohini East Metro Station, Opposite Metro Pillar No-397 Telephone: 011-65164822 Mobile: +91- 8860352748 Email: support@cpd-india.com

Editor's Notes

  • #6: Notes: A collection (sometimes called a container) is simply an object that groups multiple elements into a single unit. Collections are used to store, retrieve and manipulate data, and to transmit data from one method to another. Collections typically represent data items that form a natural group, like a poker hand (a collection of cards), a mail folder (a collection of letters), or a telephone directory (a collection of name-to-phone-number mappings).
  • #7: Notes: The Collections Framework in Java, which took shape with the release of JDK1.2 (the first Java 2 version) and expanded in 1.4 gives you lists, sets, and maps to satisfy most of your coding needs. They&amp;apos;ve been tried, tested, and tweaked. Pick the best one for your job and you&amp;apos;ll get - at the lest - reasonably good performance. And when you need something a little more custom, the Collections Framework in the java.util package is loaded with interfaces and utilities. Interfaces Interfaces allow collections to be manipulated independently of the details of their representation. In object-oriented languages like Java, these interfaces generally form a hierarchy. Implementation In essence, these are reusable data structures. Operations These algorithms are said to be polymorphic because the same method can be used on many different implementations of the appropriate collections interface. In essence, algorithms are reusable functionality
  • #11: Notes: Ordered A Hashtable collection is not ordered. Although the Hashtable itself has internal logic to determine the order (based on hashcodes), you won’t find any order when you iterate through the Hashtable. An ArrayList, however, keeps the order established by the elements’ index position (just like an array). LinkedHashSet keeps the order established by insertion, so the last element inserted is the last element in the LinkedHashSet (unlike an ArrayList where you can insert an element at a specific index position). Sorted You know how to sort alphabetically – A comes before B… For a collection of String objects, then the natural order is alphabetical. For Integer objects, the natural order is by numeric value. There is no natural order for self-defined classes unless or until the developer provides one, through an interface that defines how instances of a class can be compared to one another.
  • #15: Transition: Click the Red List Button to proceed to the topic on List. Click the Green Set Button to proceed to the topic on Set. Click the Blue Map Button to proceed to the topic on Map.
  • #16: Notes: A list cares about the index. The one thing that List has that non-lists don’t have is a set of methods related to the index. All three List implementations are ordered by index position – a position that you determine either by setting an object at a specific index or by adding it without specifying position, in which case the object is added to the end. Transition: Click ArrayList to view the sample solution. Click Vector to view the sample solution. Click Linked List to view the sample solution. Click the Red Area to go back to the previous slide.
  • #18: Vector is synchronized – only one thread can access it. Synchronization protects an object from multiple threads making modifications to an object’s state. Additionally, Hashtable is also synchronized.
  • #20: Notes: A Set cares about uniqueness – it doesn’t allow duplicates. Your good friend the equals( ) method determines whether two objects are identical (in which case only one can be in the se). The three Set implementations are described in the following sections. Transition: Click on the HashSet to view the sample solution. Click on the LinkedHashSet to view the sample solution. Click on the TreeSet to view the sample solution. Click the Green Area to go back to the previous slide.
  • #24: Notes: A Map cares about unique identifiers. You map a unique key (the ID) to a specific value, where both the key and the values are of course objects. You’re probably quite familiar with Maps since many languages support data structures that use key/value or name/value pair. Where the keys land in the Map is based on the key’s hashcode, so, like HashSet, the more efficient your hashCode( ) implementation, the better access performance you’ll get. The Map implementations let you do things like search for a value based on the key, as for a collection of just the values, or ask for a collection of just the keys. Transition: Click on the HashMap to view the sample solution. Click on the Hashtable to view the sample solution. Click on the LinkedHashMap to view the sample solution. Click on the TreeMap to view the sample solution. Click the Blue Area to go back to the previous slide.
  翻译: