SlideShare a Scribd company logo
Java Collections
APIs and Versions
• Number one hint for programming with Java
Collections: use the API
▫ http://java.sun.com/j2se/1.5.0/docs/api/java/util
/Collection.html

• Be sure to use the 1.5.0 APIs to get the version
with generics
Java Collections Framework
• The Java language API provides many of the
data structures from this class for you.
• It defines a “collection” as “an object that
represents a group of objects”.
• It defines a collections framework as “a unified
architecture for representing and manipulating
collections, allowing them to be manipulated
independent of the details of their
representation.”
Collections Framework (cont)
• Collection Interfaces - Represent different types of collections, such as sets, lists
and maps. These interfaces form the basis of the framework.
• General-purpose Implementations - Primary implementations of the collection
interfaces.
• Legacy Implementations - The collection classes from earlier releases, Vector and
Hashtable, have been retrofitted to implement the collection interfaces.
• Wrapper Implementations - Add functionality, such as synchronization, to other
implementations.
• Convenience Implementations - High-performance "mini-implementations" of
the collection interfaces.
• Abstract Implementations - Partial implementations of the collection interfaces
to facilitate custom implementations.
• Algorithms - Static methods that perform useful functions on collections, such as
sorting a list.
• Infrastructure - Interfaces that provide essential support for the collection
interfaces.
• Array Utilities - Utility functions for arrays of primitives and reference objects.
Not, strictly speaking, a part of the Collections Framework, this functionality is being
added to the Java platform at the same time and relies on some of the same
infrastructure.
Collection interfaces
• The core collection interfaces encapsulate
different types of collections. They represent the
abstract data types that are part of the
collections framework. They are interfaces so
they do not provide an implementation!
public interface Collection<E>
extends Iterable<E>
• Collection — the root of the collection hierarchy. A
collection represents a group of objects known as its
elements. The Collection interface is the least common
denominator that all collections implement and is used
to pass collections around and to manipulate them when
maximum generality is desired. Some types of
collections allow duplicate elements, and others do not.
Some are ordered and others are unordered. The Java
platform doesn't provide any direct implementations of
this interface but provides implementations of more
specific subinterfaces, such as Set and List.
A note on iterators
• An Iterator is an object that enables you to traverse
through a collection and to remove elements from the
collection selectively, if desired. You get an Iterator
for a collection by calling its iterator() method. The
following is the Iterator interface.
public interface Iterator<E> {
boolean hasNext();
E next();
void remove(); //optional
}
public interface Set<E>
• Set — a Collection<E>
extendscollection that cannot contain duplicate
elements. This interface models the
mathematical set abstraction and is used to
represent sets, such as the cards comprising a
poker hand, the courses making up a student's
schedule, or the processes running on a
machine.
public interface List<E>
extends Collection<E> (sometimes called a
• List — an ordered collection
sequence). Lists can contain duplicate elements.
The user of a List generally has precise control
over where in the list each element is inserted
and can access elements by their integer index
(position). If you've used Vector, you're familiar
with the general flavor of List.
public interface Queue<E>
extends Collection<E>

• Queue — a collection used to hold multiple
elements prior to processing. Besides basic
Collection operations, a Queue provides
additional insertion, extraction, and inspection
operations.
Note on Comparator interface
• Comparator is another interface (in addition to
Comparable) provided by the Java API which
can be used to order objects.
• You can use this interface to define an order that
is different from the Comparable (natural)
order.
public interface SortedMap<K,V>
extends Map<K,V>

• SortedMap — a Map that maintains its
mappings in ascending key order. This is the
Map analog of SortedSet. Sorted maps are used
for naturally ordered collections of key/value
pairs, such as dictionaries and telephone
directories.
General-purpose Implementations
Interfaces

Implementations
Hash table

Set

Resizable array

Linked list

TreeSet
(sorted)

HashSet

List

Tree
(sorted)

Hash table + Linked list

LinkedHashSet

LinkedList

ArrayList

Queue
Map

HashMap

TreeMap
(sorted)

LinkedHashMap

Note the naming convention
LinkedList also implements queue and there is a PriorityQueue implementation (implemented with heap)
Other implementations in the API
• Wrapper implementations delegate all their real
work to a specified collection but add (or
remove) extra functionality on top of what the
collection offers.
▫ Synchronization Wrappers
▫ Unmodifiable Wrappers

• Convenience implementations are miniimplementations that can be more convenient
and more efficient than general-purpose
implementations when you don't need their full
power
▫
▫
▫
▫

List View of an Array
Immutable Multiple-Copy List
Immutable Singleton Set
Empty Set, List, and Map Constants
public interface Map<K,V>
• Map — an object that maps keys to values. A
Map cannot contain duplicate keys; each key can
map to at most one value. If you've used
Hashtable, you're already familiar with the
basics of Map.
public interface SortedSet<E>
extends Set<E> that maintains its elements in
• SortedSet — a Set
ascending order. Several additional operations
are provided to take advantage of the ordering.
Sorted sets are used for naturally ordered
sets, such as word lists and membership rolls.
Making your own implementations
• Most of the time you can use the
implementations provided for you in the Java
API.
• In case the existing implementations do not
satisfy your needs, you can write your own by
extending the abstract classes provided in the
collections framework.

More Related Content

What's hot (20)

PDF
Java Collections Framework
guestd8c458
 
PPT
Java collection
Arati Gadgil
 
PDF
5 collection framework
Minal Maniar
 
PDF
Collections Api - Java
Drishti Bhalla
 
PPT
Collection Framework in java
CPD INDIA
 
PPTX
Collections framework in java
yugandhar vadlamudi
 
PDF
Java Collection framework
ankitgarg_er
 
PPT
Java Collections Framework
Sony India Software Center
 
PPT
Java collections concept
kumar gaurav
 
PDF
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Edureka!
 
PPTX
Java Collections Framework Inroduction with Video Tutorial
Marcus Biel
 
PPT
JAVA Collections frame work ppt
Ranjith Alappadan
 
PDF
Collections in Java Notes
Shalabh Chaudhary
 
PPTX
Java.util
Ramakrishna kapa
 
PPTX
collection framework in java
MANOJ KUMAR
 
PPSX
Collections - Lists, Sets
Hitesh-Java
 
PPT
Java collection
Deepak Kumar
 
PPTX
Java util
Srikrishna k
 
DOCX
Java collections notes
Surendar Meesala
 
Java Collections Framework
guestd8c458
 
Java collection
Arati Gadgil
 
5 collection framework
Minal Maniar
 
Collections Api - Java
Drishti Bhalla
 
Collection Framework in java
CPD INDIA
 
Collections framework in java
yugandhar vadlamudi
 
Java Collection framework
ankitgarg_er
 
Java Collections Framework
Sony India Software Center
 
Java collections concept
kumar gaurav
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Edureka!
 
Java Collections Framework Inroduction with Video Tutorial
Marcus Biel
 
JAVA Collections frame work ppt
Ranjith Alappadan
 
Collections in Java Notes
Shalabh Chaudhary
 
Java.util
Ramakrishna kapa
 
collection framework in java
MANOJ KUMAR
 
Collections - Lists, Sets
Hitesh-Java
 
Java collection
Deepak Kumar
 
Java util
Srikrishna k
 
Java collections notes
Surendar Meesala
 

Viewers also liked (11)

PPT
Java 8 Collection API Updates
Dave Leeds
 
PDF
Ajax 101 Workshop
Bill Scott
 
PPTX
Java: Collections
Arthur Emanuel
 
ODP
Preparing Java 7 Certifications
Giacomo Veneri
 
PPTX
Java simple programs
VEERA RAGAVAN
 
DOC
Advance java practicalty bscit sem5
ashish singh
 
PDF
Java Simple Programs
Upender Upr
 
PPTX
Introduction to Java Programming
One97 Communications Limited
 
PPT
Ch01 basic-java-programs
James Brotsos
 
PDF
Java Certification by HUJAK - 2015-05-12 - at JavaCro'15 conference
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
PPT
Simple Java Programs
AravindSankaran
 
Java 8 Collection API Updates
Dave Leeds
 
Ajax 101 Workshop
Bill Scott
 
Java: Collections
Arthur Emanuel
 
Preparing Java 7 Certifications
Giacomo Veneri
 
Java simple programs
VEERA RAGAVAN
 
Advance java practicalty bscit sem5
ashish singh
 
Java Simple Programs
Upender Upr
 
Introduction to Java Programming
One97 Communications Limited
 
Ch01 basic-java-programs
James Brotsos
 
Java Certification by HUJAK - 2015-05-12 - at JavaCro'15 conference
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Simple Java Programs
AravindSankaran
 
Ad

Similar to Java collections (20)

PPT
JavaCollections.ppt
Irfanhabeeb18
 
PPT
JavaCollections.ppt
boopathirajaraja1
 
PPT
Best core & advanced java classes in mumbai
Vibrant Technologies & Computers
 
PDF
Java collections
padmad2291
 
PPTX
Collections Training
Ramindu Deshapriya
 
PDF
JAVA PROGRAMMING - The Collections Framework
Jyothishmathi Institute of Technology and Science Karimnagar
 
PPT
Collections
Manav Prasad
 
PDF
Collectn framework
charan kumar
 
PDF
Collectn framework copy
charan kumar
 
PPT
Java Collection slide ppt presentation..
madduriradha
 
PPT
Collections
Rajkattamuri
 
PPTX
Collections
Marwa Dosoky
 
PPTX
oop lecture framework,list,maps,collection
ssuseredfbe9
 
PDF
Java collections framework
Fulvio Corno
 
PPTX
Java Collections Framework - Interfaces, Classes and Algorithms
RajalakshmiS74
 
PPTX
VTUOOPMCA5THMODULECollection OverV .pptx
VeenaNaik23
 
PPTX
mca5thCollection OverViCollection O.pptx
VeenaNaik23
 
PPTX
VTUOOPMCA5THMODULEvCollection OverV.pptx
VeenaNaik23
 
PPTX
VTUOOPMCA5THMODULECollection OverVi.pptx
VeenaNaik23
 
JavaCollections.ppt
Irfanhabeeb18
 
JavaCollections.ppt
boopathirajaraja1
 
Best core & advanced java classes in mumbai
Vibrant Technologies & Computers
 
Java collections
padmad2291
 
Collections Training
Ramindu Deshapriya
 
JAVA PROGRAMMING - The Collections Framework
Jyothishmathi Institute of Technology and Science Karimnagar
 
Collections
Manav Prasad
 
Collectn framework
charan kumar
 
Collectn framework copy
charan kumar
 
Java Collection slide ppt presentation..
madduriradha
 
Collections
Rajkattamuri
 
Collections
Marwa Dosoky
 
oop lecture framework,list,maps,collection
ssuseredfbe9
 
Java collections framework
Fulvio Corno
 
Java Collections Framework - Interfaces, Classes and Algorithms
RajalakshmiS74
 
VTUOOPMCA5THMODULECollection OverV .pptx
VeenaNaik23
 
mca5thCollection OverViCollection O.pptx
VeenaNaik23
 
VTUOOPMCA5THMODULEvCollection OverV.pptx
VeenaNaik23
 
VTUOOPMCA5THMODULECollection OverVi.pptx
VeenaNaik23
 
Ad

Recently uploaded (20)

PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
PDF
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PPTX
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
PDF
Complete Network Protection with Real-Time Security
L4RGINDIA
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
Complete Network Protection with Real-Time Security
L4RGINDIA
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 

Java collections

  • 2. APIs and Versions • Number one hint for programming with Java Collections: use the API ▫ http://java.sun.com/j2se/1.5.0/docs/api/java/util /Collection.html • Be sure to use the 1.5.0 APIs to get the version with generics
  • 3. Java Collections Framework • The Java language API provides many of the data structures from this class for you. • It defines a “collection” as “an object that represents a group of objects”. • It defines a collections framework as “a unified architecture for representing and manipulating collections, allowing them to be manipulated independent of the details of their representation.”
  • 4. Collections Framework (cont) • Collection Interfaces - Represent different types of collections, such as sets, lists and maps. These interfaces form the basis of the framework. • General-purpose Implementations - Primary implementations of the collection interfaces. • Legacy Implementations - The collection classes from earlier releases, Vector and Hashtable, have been retrofitted to implement the collection interfaces. • Wrapper Implementations - Add functionality, such as synchronization, to other implementations. • Convenience Implementations - High-performance "mini-implementations" of the collection interfaces. • Abstract Implementations - Partial implementations of the collection interfaces to facilitate custom implementations. • Algorithms - Static methods that perform useful functions on collections, such as sorting a list. • Infrastructure - Interfaces that provide essential support for the collection interfaces. • Array Utilities - Utility functions for arrays of primitives and reference objects. Not, strictly speaking, a part of the Collections Framework, this functionality is being added to the Java platform at the same time and relies on some of the same infrastructure.
  • 5. Collection interfaces • The core collection interfaces encapsulate different types of collections. They represent the abstract data types that are part of the collections framework. They are interfaces so they do not provide an implementation!
  • 6. public interface Collection<E> extends Iterable<E> • Collection — the root of the collection hierarchy. A collection represents a group of objects known as its elements. The Collection interface is the least common denominator that all collections implement and is used to pass collections around and to manipulate them when maximum generality is desired. Some types of collections allow duplicate elements, and others do not. Some are ordered and others are unordered. The Java platform doesn't provide any direct implementations of this interface but provides implementations of more specific subinterfaces, such as Set and List.
  • 7. A note on iterators • An Iterator is an object that enables you to traverse through a collection and to remove elements from the collection selectively, if desired. You get an Iterator for a collection by calling its iterator() method. The following is the Iterator interface. public interface Iterator<E> { boolean hasNext(); E next(); void remove(); //optional }
  • 8. public interface Set<E> • Set — a Collection<E> extendscollection that cannot contain duplicate elements. This interface models the mathematical set abstraction and is used to represent sets, such as the cards comprising a poker hand, the courses making up a student's schedule, or the processes running on a machine.
  • 9. public interface List<E> extends Collection<E> (sometimes called a • List — an ordered collection sequence). Lists can contain duplicate elements. The user of a List generally has precise control over where in the list each element is inserted and can access elements by their integer index (position). If you've used Vector, you're familiar with the general flavor of List.
  • 10. public interface Queue<E> extends Collection<E> • Queue — a collection used to hold multiple elements prior to processing. Besides basic Collection operations, a Queue provides additional insertion, extraction, and inspection operations.
  • 11. Note on Comparator interface • Comparator is another interface (in addition to Comparable) provided by the Java API which can be used to order objects. • You can use this interface to define an order that is different from the Comparable (natural) order.
  • 12. public interface SortedMap<K,V> extends Map<K,V> • SortedMap — a Map that maintains its mappings in ascending key order. This is the Map analog of SortedSet. Sorted maps are used for naturally ordered collections of key/value pairs, such as dictionaries and telephone directories.
  • 13. General-purpose Implementations Interfaces Implementations Hash table Set Resizable array Linked list TreeSet (sorted) HashSet List Tree (sorted) Hash table + Linked list LinkedHashSet LinkedList ArrayList Queue Map HashMap TreeMap (sorted) LinkedHashMap Note the naming convention LinkedList also implements queue and there is a PriorityQueue implementation (implemented with heap)
  • 14. Other implementations in the API • Wrapper implementations delegate all their real work to a specified collection but add (or remove) extra functionality on top of what the collection offers. ▫ Synchronization Wrappers ▫ Unmodifiable Wrappers • Convenience implementations are miniimplementations that can be more convenient and more efficient than general-purpose implementations when you don't need their full power ▫ ▫ ▫ ▫ List View of an Array Immutable Multiple-Copy List Immutable Singleton Set Empty Set, List, and Map Constants
  • 15. public interface Map<K,V> • Map — an object that maps keys to values. A Map cannot contain duplicate keys; each key can map to at most one value. If you've used Hashtable, you're already familiar with the basics of Map.
  • 16. public interface SortedSet<E> extends Set<E> that maintains its elements in • SortedSet — a Set ascending order. Several additional operations are provided to take advantage of the ordering. Sorted sets are used for naturally ordered sets, such as word lists and membership rolls.
  • 17. Making your own implementations • Most of the time you can use the implementations provided for you in the Java API. • In case the existing implementations do not satisfy your needs, you can write your own by extending the abstract classes provided in the collections framework.