SlideShare a Scribd company logo
1 of 17
Java Collection
Framework
History
• Before JDK 1.2 introduced, the standard methods for grouping Java
objects were Arrays or Vectors, or Hashtables.
• Those method had no common interface, defined independently and
had no correlation among them
• Very difficult to remember all the different methods, syntax,
and constructors
7/26/2023 JAVA COLLECTION FRAMEWORK 2
History
• To represent a group of objects as a single entity in the Java
programming language we need classes and interfaces defined by
the Collection Framework
7/26/2023 JAVA COLLECTION FRAMEWORK 3
Collection Framework Taxonomy
Source: https://www.geeksforgeeks.org/java-collection-tutorial/
7/26/2023 JAVA COLLECTION FRAMEWORK 4
What is Collection?
• A collection 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
7/26/2023 JAVA COLLECTION FRAMEWORK 5
Set
• Set Interface: A set is a collection that cannot contain any
duplicate elements.
• This interface models the mathematical set abstraction.
• Set Interface extends Collection Interface.
• A set contains no pair of elements e1 and e2 such that
e1.equals(e2), and at most one null element.
7/26/2023 JAVA COLLECTION FRAMEWORK 6
HashSet
• The class HashSet implements the Set Interface.
• This class maintains a collection of individual objects and
you can do intersection, set difference and iteration over
the collection. The hash table makes this operations fast.
• This class permits the null element.
• HashSet makes no guarantees as to the iteration order of
the set, in particular, it does not guarantee that the order
will remain constant over time.
7/26/2023 JAVA COLLECTION FRAMEWORK 7
TreeSet
• TreeSet: this class implements Set interface, backed by a
TreeMap instance.
• TreeSet guarantees that the sorted set will be in
ascending element order, sorted according to the natural
order of the elements, or by the comparator provided at
set creation, depending on which constructor is used.
7/26/2023 JAVA COLLECTION FRAMEWORK 8
List
• List: a List is an ordered collection.
• The user has precise control over where in the list each
element is inserted.
• The user can access the elements by their integer index
and search for elements in the list.
• Unlike sets, lists typically allow duplicate elements.
• Array List, Vector and Linked List are implementations of
List Interface.
7/26/2023 JAVA COLLECTION FRAMEWORK 9
Map
• Map Interface: a Map is a object that maps keys to
values.
• A Map cannot contain duplicate keys, each key can map
to utmost one value.
• Map does not implement collection interface.
• This interface provides three collection views, which allow
viewing a map's contents as a set of keys, a collection of
values or a set of key value pairs.
• Set and Map collections ensure uniqueness, List
Collections do not ensure uniqueness but are sorted.
7/26/2023 JAVA COLLECTION FRAMEWORK 10
Utility Classes
• public interface Enumeration
• An object that implements the Enumeration interface
generates a series of elements, one at a time. Successive
calls to the nextElement method return successive
elements of the series.
• hasMoreElements()
7/26/2023 JAVA COLLECTION FRAMEWORK 11
Utility Classes Example
7/26/2023 JAVA COLLECTION FRAMEWORK 12
Iterator
• public interface Iterator
• An iterator over a collection. Iterator takes the place of
Enumeration in the Java collections framework. Iterators
differ from enumerations in two ways:
• Iterators allow the caller to remove elements from the underlying
collection during the iteration with well-defined semantics.
• Method names have been improved.
7/26/2023 JAVA COLLECTION FRAMEWORK 13
Iterator Example
7/26/2023 JAVA COLLECTION FRAMEWORK 14
LinkedHashMap Example
7/26/2023 JAVA COLLECTION FRAMEWORK 15
Exercise
• Create an interface called Transaction that contains two
methods: getQuantity and getValue.
• Create Purchase and Sale class that implement
Transaction interface.
• In your program, fill a list with Purchase and Sale objects
with random value, and then create two method:
getTotalQuantity and getTotalValue(), where their values
calculated using Transaction interface.
7/26/2023 JAVA COLLECTION FRAMEWORK 16
Thank you
Bayu Rimba Pratama, ST, M.Kom

More Related Content

Similar to Slide Dasar Materi Java Collection Framework

Similar to Slide Dasar Materi Java Collection Framework (20)

JAVA(UNIT 4)
JAVA(UNIT 4)JAVA(UNIT 4)
JAVA(UNIT 4)
 
5 collection framework
5 collection framework5 collection framework
5 collection framework
 
Collections
CollectionsCollections
Collections
 
11000121065_NAITIK CHATTERJEE.ppt
11000121065_NAITIK CHATTERJEE.ppt11000121065_NAITIK CHATTERJEE.ppt
11000121065_NAITIK CHATTERJEE.ppt
 
Collectn framework copy
Collectn framework   copyCollectn framework   copy
Collectn framework copy
 
Collectn framework
Collectn frameworkCollectn framework
Collectn framework
 
Week_2_Lec_6-10_with_watermarking_(1).pdf
Week_2_Lec_6-10_with_watermarking_(1).pdfWeek_2_Lec_6-10_with_watermarking_(1).pdf
Week_2_Lec_6-10_with_watermarking_(1).pdf
 
Java Collection Interview Questions [Updated]
Java Collection Interview Questions [Updated]Java Collection Interview Questions [Updated]
Java Collection Interview Questions [Updated]
 
Learn advanced java programming
Learn advanced java programmingLearn advanced java programming
Learn advanced java programming
 
Collections
CollectionsCollections
Collections
 
collection framework.pptx
collection framework.pptxcollection framework.pptx
collection framework.pptx
 
Collections framework in java
Collections framework in javaCollections framework in java
Collections framework in java
 
Collections in Java Notes
Collections in Java NotesCollections in Java Notes
Collections in Java Notes
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
Java Collection
Java CollectionJava Collection
Java Collection
 
Java collections
Java collectionsJava collections
Java collections
 
Collection framework
Collection frameworkCollection framework
Collection framework
 
Java collection
Java collectionJava collection
Java collection
 
24 collections framework interview questions
24 collections framework interview questions24 collections framework interview questions
24 collections framework interview questions
 
Java Collections
Java CollectionsJava Collections
Java Collections
 

More from Bayu Rimba

Slide Presentasi Dasar-dasar Flowchart
Slide Presentasi Dasar-dasar FlowchartSlide Presentasi Dasar-dasar Flowchart
Slide Presentasi Dasar-dasar FlowchartBayu Rimba
 
Slide Tugas Algoritma dan Pemrograman
Slide Tugas Algoritma dan PemrogramanSlide Tugas Algoritma dan Pemrograman
Slide Tugas Algoritma dan PemrogramanBayu Rimba
 
Slide Presentasi Teknik OO pada Desain Software
Slide Presentasi Teknik OO pada Desain SoftwareSlide Presentasi Teknik OO pada Desain Software
Slide Presentasi Teknik OO pada Desain SoftwareBayu Rimba
 
Slide Latihan JDBC bagian 2
Slide Latihan JDBC bagian 2Slide Latihan JDBC bagian 2
Slide Latihan JDBC bagian 2Bayu Rimba
 
Slide Latihan JDBC
Slide Latihan JDBCSlide Latihan JDBC
Slide Latihan JDBCBayu Rimba
 
Presentasi latihan pemrograman Java GUI menggunakan SWING
Presentasi latihan pemrograman Java GUI menggunakan SWINGPresentasi latihan pemrograman Java GUI menggunakan SWING
Presentasi latihan pemrograman Java GUI menggunakan SWINGBayu Rimba
 

More from Bayu Rimba (6)

Slide Presentasi Dasar-dasar Flowchart
Slide Presentasi Dasar-dasar FlowchartSlide Presentasi Dasar-dasar Flowchart
Slide Presentasi Dasar-dasar Flowchart
 
Slide Tugas Algoritma dan Pemrograman
Slide Tugas Algoritma dan PemrogramanSlide Tugas Algoritma dan Pemrograman
Slide Tugas Algoritma dan Pemrograman
 
Slide Presentasi Teknik OO pada Desain Software
Slide Presentasi Teknik OO pada Desain SoftwareSlide Presentasi Teknik OO pada Desain Software
Slide Presentasi Teknik OO pada Desain Software
 
Slide Latihan JDBC bagian 2
Slide Latihan JDBC bagian 2Slide Latihan JDBC bagian 2
Slide Latihan JDBC bagian 2
 
Slide Latihan JDBC
Slide Latihan JDBCSlide Latihan JDBC
Slide Latihan JDBC
 
Presentasi latihan pemrograman Java GUI menggunakan SWING
Presentasi latihan pemrograman Java GUI menggunakan SWINGPresentasi latihan pemrograman Java GUI menggunakan SWING
Presentasi latihan pemrograman Java GUI menggunakan SWING
 

Recently uploaded

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 

Slide Dasar Materi Java Collection Framework

  • 2. History • Before JDK 1.2 introduced, the standard methods for grouping Java objects were Arrays or Vectors, or Hashtables. • Those method had no common interface, defined independently and had no correlation among them • Very difficult to remember all the different methods, syntax, and constructors 7/26/2023 JAVA COLLECTION FRAMEWORK 2
  • 3. History • To represent a group of objects as a single entity in the Java programming language we need classes and interfaces defined by the Collection Framework 7/26/2023 JAVA COLLECTION FRAMEWORK 3
  • 4. Collection Framework Taxonomy Source: https://www.geeksforgeeks.org/java-collection-tutorial/ 7/26/2023 JAVA COLLECTION FRAMEWORK 4
  • 5. What is Collection? • A collection 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 7/26/2023 JAVA COLLECTION FRAMEWORK 5
  • 6. Set • Set Interface: A set is a collection that cannot contain any duplicate elements. • This interface models the mathematical set abstraction. • Set Interface extends Collection Interface. • A set contains no pair of elements e1 and e2 such that e1.equals(e2), and at most one null element. 7/26/2023 JAVA COLLECTION FRAMEWORK 6
  • 7. HashSet • The class HashSet implements the Set Interface. • This class maintains a collection of individual objects and you can do intersection, set difference and iteration over the collection. The hash table makes this operations fast. • This class permits the null element. • HashSet makes no guarantees as to the iteration order of the set, in particular, it does not guarantee that the order will remain constant over time. 7/26/2023 JAVA COLLECTION FRAMEWORK 7
  • 8. TreeSet • TreeSet: this class implements Set interface, backed by a TreeMap instance. • TreeSet guarantees that the sorted set will be in ascending element order, sorted according to the natural order of the elements, or by the comparator provided at set creation, depending on which constructor is used. 7/26/2023 JAVA COLLECTION FRAMEWORK 8
  • 9. List • List: a List is an ordered collection. • The user has precise control over where in the list each element is inserted. • The user can access the elements by their integer index and search for elements in the list. • Unlike sets, lists typically allow duplicate elements. • Array List, Vector and Linked List are implementations of List Interface. 7/26/2023 JAVA COLLECTION FRAMEWORK 9
  • 10. Map • Map Interface: a Map is a object that maps keys to values. • A Map cannot contain duplicate keys, each key can map to utmost one value. • Map does not implement collection interface. • This interface provides three collection views, which allow viewing a map's contents as a set of keys, a collection of values or a set of key value pairs. • Set and Map collections ensure uniqueness, List Collections do not ensure uniqueness but are sorted. 7/26/2023 JAVA COLLECTION FRAMEWORK 10
  • 11. Utility Classes • public interface Enumeration • An object that implements the Enumeration interface generates a series of elements, one at a time. Successive calls to the nextElement method return successive elements of the series. • hasMoreElements() 7/26/2023 JAVA COLLECTION FRAMEWORK 11
  • 12. Utility Classes Example 7/26/2023 JAVA COLLECTION FRAMEWORK 12
  • 13. Iterator • public interface Iterator • An iterator over a collection. Iterator takes the place of Enumeration in the Java collections framework. Iterators differ from enumerations in two ways: • Iterators allow the caller to remove elements from the underlying collection during the iteration with well-defined semantics. • Method names have been improved. 7/26/2023 JAVA COLLECTION FRAMEWORK 13
  • 14. Iterator Example 7/26/2023 JAVA COLLECTION FRAMEWORK 14
  • 15. LinkedHashMap Example 7/26/2023 JAVA COLLECTION FRAMEWORK 15
  • 16. Exercise • Create an interface called Transaction that contains two methods: getQuantity and getValue. • Create Purchase and Sale class that implement Transaction interface. • In your program, fill a list with Purchase and Sale objects with random value, and then create two method: getTotalQuantity and getTotalValue(), where their values calculated using Transaction interface. 7/26/2023 JAVA COLLECTION FRAMEWORK 16
  • 17. Thank you Bayu Rimba Pratama, ST, M.Kom