This document provides a quick introduction to Java collections, including the core Collection interface and three main collection types: List, Set, and Map. It describes some key methods of the Collection interface like add(), remove(), and contains(). It also outlines some common concrete classes that implement the List, Set, and Map interfaces, such as ArrayList, LinkedList, HashSet, TreeSet, HashMap, and TreeMap. The document concludes by demonstrating how to iterate over a collection using an Iterator.
CNIC Information System with Pakdata Cf In Pakistan
Quick Intro to Java Collections
1. Quick
Intro
to
Java
Collec2ons
Jussi
Pohjolainen
Tampere
University
of
Applied
Sciences
2. Intro
• Java
Collec2on
Framework
is
a
set
of
classes
and
interfaces
to
implement
data
structures
• When
array
is
not
enough..
J
• Lot
of
classes
and
interfaces
– hFp://upload.wikimedia.org/wikipedia/
commons/4/41/Collec2on_Classes.jpg
4. Collec2on
Interface
• Basic
parts
of
all
collec2ons
• add(),
remove(),
toArray(),
contains()
• Collec2on
is
generic
5. Three
main
type
of
Collec2on
• List
– Always
ordered,
may
contain
duplicates,
like
an
array
• Set
– Cannot
contain
duplicate
• Map
– Key
–
value
pairs,
random
access
to
keys
6. List
• List
interface
has
two
concrete
classes
– ArrayList
–
implementa2on
uses
dynamically
resized
arrays
– LinkedList
–
double-‐linked
list
7. Set
• Set
can’t
have
duplicates
• Couple
concrete
classes
– HashSet
– TreeSet
–
sorted
elements!