SlideShare a Scribd company logo
JAVA PROGRAMMING
COLLECTION FRAMEWORK
GOVT.POLYTECHNIC
AURAI
1
CONTENTS
• Introduction
• What is Collection
• Collections Framework
•Collections Hierarchy
• Set
• List
• Map
2
COLLECTION FRAMEWORK
 The collections framework define a set of interfaces and their
implementations to manipulate collection.
The collection framework also allows us to store , retrieve, and update
a set of objects.
 It reduces programming effort while increasing performance.
It provides an API to work with the data structure, such as lists , tree,
maps, and sets.
3
The collection framework which is contained in the java.util
package is one of java’s most powerful sub-systems.
It includes implementations of these interfaces and algorithms
to manipulate them.
Which server as a container for a group of object such as a set of
words in a dictionary or a collection.
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
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.
Core Interface Description
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. 10
• Remove object from collection
• Iterate collection and inspect each object
• Each operation has a corresponding method implementation
for each collection type
11
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.
12
ITERATOR
 The Iterator interface enables us to sequentially traverse
and access the elements contained in a collection .
 The elements of a collection can be accessed using the
methods defined by the Iterator interface.
Syntax:
Iterator <variable> = <CollectionObject>.iterator();
13
Method Defined in the Iterator Interface
Method Description
hasNext() :- Return true if the collection contains more then one element.
next() :- Returns the next element form the collection.
remove() :- Remove the current element from the collection.
14
COLLECTIONS HIERARCHY
SET AND LIST
Collection
Set List
Implements
HashSet
SortedSet
Implements
extends
LimkedHashSet TreeSet LinkedList Vector ArrayList
extends
Implements
Implements
15
COLLECTIONS HIERARCHY
MAP
Collection
Implements
Hashtable
LinkedHashMap
HashMap
extends
TreeMap
SortedMap
extends
Implements
16
COLLECTION IMPLEMENTATIONS
List:- List of things(classes that implement List)
Set:-Unique things(classes that implement set)
Map:-Things with a unique ID(classes that implement Map)
17
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
19
LIST IMPLEMENTATIONS
VECTOR
Import java.util.Vector;
public class MyVector {
public static void main(string args[ ]) {
Vector vecky=newVector( );
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
20
LIST IMPLEMENTATIONS
LINKEDLIST
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
21
SET
A set cares about uniqueness. It doesn’t allow duplicates.
“Paul”
“Peter”
“John”
“Mark”
“Luke”
“Fred”
HashSet LinkedHashSet Treeset 22
LIST IMPLEMENTATIONS
HASHSET
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.hashnext( ) ) {
system.out.println( iterator.next( ) );
}
}
}
d
a
c
b
23
LIST IMPLEMENTATIONS
LINKEDHASHSET
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
24
import java.util.TreeSet;
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( ));
}
}
}
SET IMPLEMENTATIONS
TREE SET
Jody
Philippe
Reggie
Remiel
25
A map cares about unique identifier.
Key:
Value: “Paul” “Mark” “John” “Paul” “Luke”
HashMap Hashtable LinkedHashMap
“PI” “Ma” “Jn” “ul” “Le”
TreeMap 26
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
27
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}28
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
29
MAP IMPLEMENTATIONS
TREE MAP
import 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 theVALUES....
Manila
446
Jody
30
COLLECTION CLASSES SUMMARY
Class Map Set List Ordered Sorted
HashMap X No No
Hashtable X No No
TreeMap X Sorted By natural order or
custom comparison rules
LinkedHashmap X By insertion order or No
last access order
HashSet X No No
TreeSet X Sorted By natural order or
custom comparison rules
LinkedHashSet X By insertion order or No
last access order
ArrayList X By Index No
Vector X By Index No
LinkedList X By Index No
31
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.
32
THANKS
YOU
33

More Related Content

What's hot

Java collections concept
Java collections conceptJava collections concept
Java collections concept
kumar gaurav
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
Sony India Software Center
 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
Prof. Erwin Globio
 
Java Collections
Java  Collections Java  Collections
Java collections
Java collectionsJava collections
Java collections
Hamid Ghorbani
 
Collections in Java Notes
Collections in Java NotesCollections in Java Notes
Collections in Java Notes
Shalabh Chaudhary
 
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!
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets
Hitesh-Java
 
5 collection framework
5 collection framework5 collection framework
5 collection framework
Minal Maniar
 
Java ArrayList Tutorial | Edureka
Java ArrayList Tutorial | EdurekaJava ArrayList Tutorial | Edureka
Java ArrayList Tutorial | Edureka
Edureka!
 
How Hashmap works internally in java
How Hashmap works internally  in javaHow Hashmap works internally  in java
How Hashmap works internally in java
Ramakrishna Joshi
 
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 Stack Data Structure.pptx
Java Stack Data Structure.pptxJava Stack Data Structure.pptx
Java Stack Data Structure.pptx
vishal choudhary
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
Naz Abdalla
 
Wrapper class
Wrapper classWrapper class
Wrapper class
kamal kotecha
 
Collections In Java
Collections In JavaCollections In Java
Collections In JavaBinoj T E
 
Java Stack Data Structure.pptx
Java Stack Data Structure.pptxJava Stack Data Structure.pptx
Java Stack Data Structure.pptx
vishal choudhary
 
Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
 
Collections and generics
Collections and genericsCollections and generics
Collections and generics
Muthukumaran Subramanian
 

What's hot (20)

Java collections concept
Java collections conceptJava collections concept
Java collections concept
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
Java collections
Java collectionsJava collections
Java collections
 
Collections in Java Notes
Collections in Java NotesCollections in Java Notes
Collections in Java Notes
 
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...
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets
 
5 collection framework
5 collection framework5 collection framework
5 collection framework
 
Java ArrayList Tutorial | Edureka
Java ArrayList Tutorial | EdurekaJava ArrayList Tutorial | Edureka
Java ArrayList Tutorial | Edureka
 
Generics
GenericsGenerics
Generics
 
How Hashmap works internally in java
How Hashmap works internally  in javaHow Hashmap works internally  in java
How Hashmap works internally in java
 
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 Stack Data Structure.pptx
Java Stack Data Structure.pptxJava Stack Data Structure.pptx
Java Stack Data Structure.pptx
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
Collections In Java
Collections In JavaCollections In Java
Collections In Java
 
Java Stack Data Structure.pptx
Java Stack Data Structure.pptxJava Stack Data Structure.pptx
Java Stack Data Structure.pptx
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Collections and generics
Collections and genericsCollections and generics
Collections and generics
 

Similar to collection framework in java

collectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptxcollectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptx
hemanth248901
 
DSJ_Unit III_Collection framework.pdf
DSJ_Unit III_Collection framework.pdfDSJ_Unit III_Collection framework.pdf
DSJ_Unit III_Collection framework.pdf
Arumugam90
 
Collections generic
Collections genericCollections generic
Collections generic
sandhish
 
22.ppt
22.ppt22.ppt
Collections Framework
Collections FrameworkCollections Framework
Collections Framework
Sunil OS
 
ArrayList.docx
ArrayList.docxArrayList.docx
ArrayList.docx
veerendranath12
 
javacollections.pdf
javacollections.pdfjavacollections.pdf
javacollections.pdf
ManojKandhasamy1
 
Collections framework
Collections frameworkCollections framework
Collections framework
Anand Buddarapu
 
12_-_Collections_Framework
12_-_Collections_Framework12_-_Collections_Framework
12_-_Collections_FrameworkKrishna Sujeer
 
Collections in .net technology (2160711)
Collections in .net technology (2160711)Collections in .net technology (2160711)
Collections in .net technology (2160711)
Janki Shah
 
Collections
CollectionsCollections
Collections
Manav Prasad
 
Collections - Lists & sets
Collections - Lists & setsCollections - Lists & sets
Collections - Lists & sets
RatnaJava
 
Collections in Java
Collections in JavaCollections in Java
Collections in Java
Khasim Cise
 
Collections
CollectionsCollections
Collections
Rajkattamuri
 
Collection Framework-1.pptx
Collection Framework-1.pptxCollection Framework-1.pptx
Collection Framework-1.pptx
SarthakSrivastava70
 
collections
collectionscollections
collections
javeed_mhd
 
oop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionoop lecture framework,list,maps,collection
oop lecture framework,list,maps,collection
ssuseredfbe9
 

Similar to collection framework in java (20)

collectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptxcollectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptx
 
DSJ_Unit III_Collection framework.pdf
DSJ_Unit III_Collection framework.pdfDSJ_Unit III_Collection framework.pdf
DSJ_Unit III_Collection framework.pdf
 
Collections generic
Collections genericCollections generic
Collections generic
 
22.ppt
22.ppt22.ppt
22.ppt
 
Collections Framework
Collections FrameworkCollections Framework
Collections Framework
 
ArrayList.docx
ArrayList.docxArrayList.docx
ArrayList.docx
 
javacollections.pdf
javacollections.pdfjavacollections.pdf
javacollections.pdf
 
Collections framework
Collections frameworkCollections framework
Collections framework
 
12_-_Collections_Framework
12_-_Collections_Framework12_-_Collections_Framework
12_-_Collections_Framework
 
Collections in .net technology (2160711)
Collections in .net technology (2160711)Collections in .net technology (2160711)
Collections in .net technology (2160711)
 
Collections
CollectionsCollections
Collections
 
Presentation1
Presentation1Presentation1
Presentation1
 
Collections - Lists & sets
Collections - Lists & setsCollections - Lists & sets
Collections - Lists & sets
 
Collections in Java
Collections in JavaCollections in Java
Collections in Java
 
Collections
CollectionsCollections
Collections
 
Collection Framework-1.pptx
Collection Framework-1.pptxCollection Framework-1.pptx
Collection Framework-1.pptx
 
Collections
CollectionsCollections
Collections
 
collections
collectionscollections
collections
 
oop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionoop lecture framework,list,maps,collection
oop lecture framework,list,maps,collection
 
16 containers
16   containers16   containers
16 containers
 

Recently uploaded

LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
ssuser9bd3ba
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
MuhammadTufail242431
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
abh.arya
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
Kamal Acharya
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
PrashantGoswami42
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 

Recently uploaded (20)

LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 

collection framework in java

  • 2. CONTENTS • Introduction • What is Collection • Collections Framework •Collections Hierarchy • Set • List • Map 2
  • 3. COLLECTION FRAMEWORK  The collections framework define a set of interfaces and their implementations to manipulate collection. The collection framework also allows us to store , retrieve, and update a set of objects.  It reduces programming effort while increasing performance. It provides an API to work with the data structure, such as lists , tree, maps, and sets. 3
  • 4. The collection framework which is contained in the java.util package is one of java’s most powerful sub-systems. It includes implementations of these interfaces and algorithms to manipulate them. Which server as a container for a group of object such as a set of words in a dictionary or a collection. 4
  • 5. OBJECTIVES Define a collection. Describe the collections framework. Describe the collections hierarchy. Demonstrate each collection implementation. 5
  • 6. 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
  • 7. 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
  • 8. COLLECTIONS FRAMEWORK INTERFACES 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. Core Interface Description 8
  • 9. 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
  • 10. 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. 10
  • 11. • Remove object from collection • Iterate collection and inspect each object • Each operation has a corresponding method implementation for each collection type 11
  • 12. 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. 12
  • 13. ITERATOR  The Iterator interface enables us to sequentially traverse and access the elements contained in a collection .  The elements of a collection can be accessed using the methods defined by the Iterator interface. Syntax: Iterator <variable> = <CollectionObject>.iterator(); 13
  • 14. Method Defined in the Iterator Interface Method Description hasNext() :- Return true if the collection contains more then one element. next() :- Returns the next element form the collection. remove() :- Remove the current element from the collection. 14
  • 15. COLLECTIONS HIERARCHY SET AND LIST Collection Set List Implements HashSet SortedSet Implements extends LimkedHashSet TreeSet LinkedList Vector ArrayList extends Implements Implements 15
  • 17. COLLECTION IMPLEMENTATIONS List:- List of things(classes that implement List) Set:-Unique things(classes that implement set) Map:-Things with a unique ID(classes that implement Map) 17
  • 18. 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 19
  • 19. LIST IMPLEMENTATIONS VECTOR Import java.util.Vector; public class MyVector { public static void main(string args[ ]) { Vector vecky=newVector( ); 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 20
  • 20. LIST IMPLEMENTATIONS LINKEDLIST 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 21
  • 21. SET A set cares about uniqueness. It doesn’t allow duplicates. “Paul” “Peter” “John” “Mark” “Luke” “Fred” HashSet LinkedHashSet Treeset 22
  • 22. LIST IMPLEMENTATIONS HASHSET 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.hashnext( ) ) { system.out.println( iterator.next( ) ); } } } d a c b 23
  • 23. LIST IMPLEMENTATIONS LINKEDHASHSET 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 24
  • 24. import java.util.TreeSet; 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( )); } } } SET IMPLEMENTATIONS TREE SET Jody Philippe Reggie Remiel 25
  • 25. A map cares about unique identifier. Key: Value: “Paul” “Mark” “John” “Paul” “Luke” HashMap Hashtable LinkedHashMap “PI” “Ma” “Jn” “ul” “Le” TreeMap 26
  • 26. 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 27
  • 27. 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}28
  • 28. 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 29
  • 29. MAP IMPLEMENTATIONS TREE MAP import 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 theVALUES.... Manila 446 Jody 30
  • 30. COLLECTION CLASSES SUMMARY Class Map Set List Ordered Sorted HashMap X No No Hashtable X No No TreeMap X Sorted By natural order or custom comparison rules LinkedHashmap X By insertion order or No last access order HashSet X No No TreeSet X Sorted By natural order or custom comparison rules LinkedHashSet X By insertion order or No last access order ArrayList X By Index No Vector X By Index No LinkedList X By Index No 31
  • 31. 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. 32