You are on page 1of 104

Java Collections Framework

Marcus Biel, Software Craftsman


http://www.marcus-biel.com
Collection(s)

2. Java Collections Framework

3. a data structure

4. java.util.Collection interface

5. java.util.Collections
Collection(s)
1. a compilation or group of things

2. Java Collections Framework

3. a data structure

4. java.util.Collection interface

5. java.util.Collections
Collection(s)
1. a compilation or group of things

2. Java Collections Framework

3. a data structure

4. java.util.Collection interface

5. java.util.Collections
Collection(s)
1. a compilation or group of things

2. Java Collections Framework

3. a data structure

4. java.util.Collection interface

5. java.util.Collections
Collection(s)
1. a compilation or group of things

2. Java Collections Framework

3. a data structure

4. java.util.Collection interface

5. java.util.Collections
Collection(s)
1. a compilation or group of things

2. Java Collections Framework

3. a data structure

4. java.util.Collection interface

5. java.util.Collections
What is the Java Collections Framework?
What is the Java Collections Framework?
A toolbox of generic interfaces and classes
What is the Java Collections Framework?
A toolbox of generic interfaces and classes
• collection interfaces and classes
What is the Java Collections Framework?
A toolbox of generic interfaces and classes
• collection interfaces and classes
• collection related utility interfaces classes
Collections interface and class hierarchy

<<interface>> <<interface>>
Collection Map
Collections interface and class hierarchy

<<interface>> <<interface>>
Collection Map
Collections interface and class hierarchy

<<interface>> <<interface>>
Collection Map
Collection Interface
<<interface>>
Collection

<<interface>> <<interface>> <<interface>>


Set List Queue

<<interface>>
HashSet ArrayList Vector LinkedList PriorityQueue
SortedSet

<<interface>>
LinkedHashSet
NavigableSet implements
extends
TreeSet
Collection Interface
<<interface>>
Collection

<<interface>> <<interface>> <<interface>>


Set List Queue

<<interface>>
HashSet ArrayList Vector LinkedList PriorityQueue
SortedSet

<<interface>>
LinkedHashSet
NavigableSet implements
extends
TreeSet
Collection Interface
<<interface>>
Collection

<<interface>> <<interface>> <<interface>>


Set List Queue

<<interface>>
HashSet ArrayList Vector LinkedList PriorityQueue
SortedSet

<<interface>>
LinkedHashSet
NavigableSet implements
extends
TreeSet
Collection Interface
<<interface>>
Collection

<<interface>> <<interface>> <<interface>>


Set List Queue

<<interface>>
HashSet ArrayList Vector LinkedList PriorityQueue
SortedSet

<<interface>>
LinkedHashSet
NavigableSet implements
extends
TreeSet
Collection Interface
<<interface>>
Collection

<<interface>> <<interface>> <<interface>>


Set List Queue

<<interface>>
HashSet ArrayList Vector LinkedList PriorityQueue
SortedSet

<<interface>>
LinkedHashSet
NavigableSet implements
extends
TreeSet
Collection Interface
<<interface>>
Collection

<<interface>> <<interface>> <<interface>>


Set List Queue

<<interface>>
HashSet ArrayList Vector LinkedList PriorityQueue
SortedSet

<<interface>>
LinkedHashSet
NavigableSet implements
extends
TreeSet
Collection Interface
<<interface>>
Collection

<<interface>> <<interface>> <<interface>>


Set List Queue

<<interface>>
HashSet ArrayList Vector LinkedList PriorityQueue
SortedSet

<<interface>>
LinkedHashSet
NavigableSet implements
extends
TreeSet
Collection Interface
<<interface>>
Collection

<<interface>> <<interface>> <<interface>>


Set List Queue

<<interface>>
HashSet ArrayList Vector LinkedList PriorityQueue
SortedSet

<<interface>>
LinkedHashSet
NavigableSet implements
extends
TreeSet
Collection Interface
<<interface>>
Collection

<<interface>> <<interface>> <<interface>>


Set List Queue

<<interface>>
HashSet ArrayList Vector LinkedList PriorityQueue
SortedSet

<<interface>>
LinkedHashSet
NavigableSet implements
extends
TreeSet
Collection Interface
<<interface>>
Collection

<<interface>> <<interface>> <<interface>>


Set List Queue

<<interface>>
HashSet ArrayList Vector LinkedList PriorityQueue
SortedSet

<<interface>>
LinkedHashSet
NavigableSet implements
extends
TreeSet
Collection Interface
<<interface>>
Collection

<<interface>> <<interface>> <<interface>>


Set List Queue

<<interface>>
HashSet ArrayList Vector LinkedList PriorityQueue
SortedSet

<<interface>>
LinkedHashSet
NavigableSet implements
extends
TreeSet
Collection Interface
<<interface>>
Collection

<<interface>> <<interface>> <<interface>>


Set List Queue

<<interface>>
HashSet ArrayList Vector LinkedList PriorityQueue
SortedSet

<<interface>>
LinkedHashSet
NavigableSet implements
extends
TreeSet
Collection Interface
<<interface>>
Collection

<<interface>> <<interface>> <<interface>>


Set List Queue

<<interface>>
HashSet ArrayList Vector LinkedList PriorityQueue
SortedSet

<<interface>>
LinkedHashSet
NavigableSet implements
extends
TreeSet
Collection Interface
<<interface>>
Collection

<<interface>> <<interface>> <<interface>>


Set List Queue

<<interface>>
HashSet ArrayList Vector LinkedList PriorityQueue
SortedSet

<<interface>>
LinkedHashSet
NavigableSet implements
extends
TreeSet
Collection Interface
<<interface>>
Collection

<<interface>> <<interface>> <<interface>>


Set List Queue

<<interface>>
HashSet ArrayList Vector LinkedList PriorityQueue
SortedSet

<<interface>>
LinkedHashSet
NavigableSet implements
extends
TreeSet
Collection Interface
<<interface>>
Collection

<<interface>> <<interface>> <<interface>>


Set List Queue

<<interface>>
HashSet ArrayList Vector LinkedList PriorityQueue
SortedSet

<<interface>>
LinkedHashSet
NavigableSet implements
extends
TreeSet
Collection Interface
<<interface>>
Collection

<<interface>> <<interface>> <<interface>>


Set List Queue

<<interface>>
HashSet ArrayList Vector LinkedList PriorityQueue
SortedSet

<<interface>>
LinkedHashSet
NavigableSet implements
extends
TreeSet
Collection Interface
<<interface>>
Collection

<<interface>> <<interface>> <<interface>>


Set List Queue

<<interface>>
HashSet ArrayList Vector LinkedList PriorityQueue
SortedSet

<<interface>>
LinkedHashSet
NavigableSet implements
extends
TreeSet
Collection Interface
<<interface>>
Collection

<<interface>> <<interface>> <<interface>>


Set List Queue

<<interface>>
HashSet ArrayList LinkedList PriorityQueue
SortedSet

<<interface>>
LinkedHashSet
NavigableSet implements
extends
TreeSet
Collection Interface
<<interface>>
Collection

<<interface>> <<interface>> <<interface>>


Set List Queue

<<interface>>
HashSet ArrayList LinkedList PriorityQueue
SortedSet

<<interface>>
LinkedHashSet
NavigableSet implements
extends
TreeSet
Collection Interface
<<interface>>
Collection

<<interface>> <<interface>> <<interface>>


Set List Queue

<<interface>>
HashSet ArrayList LinkedList PriorityQueue
SortedSet

<<interface>>
LinkedHashSet
NavigableSet implements
extends
TreeSet
Collection Interface
<<interface>>
Collection

<<interface>> <<interface>> <<interface>>


Set List Queue

<<interface>>
HashSet ArrayList LinkedList PriorityQueue
SortedSet

<<interface>>
LinkedHashSet
NavigableSet implements
extends
TreeSet
Collection Interface
<<interface>>
Collection

<<interface>> <<interface>> <<interface>>


Set List Queue

<<interface>>
HashSet ArrayList LinkedList PriorityQueue
SortedSet

<<interface>>
LinkedHashSet
NavigableSet implements
extends
TreeSet
Map Interface
<<interface>>
Map

<<interface>>
SortedMap

<<interface>>
Hashtable Hashmap
NavigableMap

implements LinkedHashMap TreeMap


extends
Map Interface
<<interface>>
Map

<<interface>>
SortedMap

<<interface>>
Hashtable Hashmap
NavigableMap

implements LinkedHashMap TreeMap


extends
Map Interface
<<interface>>
Map

<<interface>>
SortedMap

<<interface>>
Hashtable Hashmap
NavigableMap

implements LinkedHashMap TreeMap


extends
Map Interface
<<interface>>
Map

<<interface>>
SortedMap

<<interface>>
Hashtable Hashmap
NavigableMap

implements LinkedHashMap TreeMap


extends
Map Interface
<<interface>>
Map

<<interface>>
SortedMap

<<interface>>
Hashtable Hashmap
NavigableMap

implements LinkedHashMap TreeMap


extends
Map Interface
<<interface>>
Map

<<interface>>
SortedMap

<<interface>>
Hashmap
NavigableMap

implements LinkedHashMap TreeMap


extends
Map Interface
<<interface>>
Map

<<interface>>
SortedMap

<<interface>>
Hashmap
NavigableMap

implements LinkedHashMap TreeMap


extends
Map Interface
<<interface>>
Map

<<interface>>
SortedMap

<<interface>>
Hashmap
NavigableMap

implements LinkedHashMap TreeMap


extends
Map Interface
<<interface>>
Map

<<interface>>
SortedMap

<<interface>>
Hashmap
NavigableMap

implements LinkedHashMap TreeMap


extends
Map Interface
<<interface>>
Map

<<interface>>
SortedMap

<<interface>>
Hashmap
NavigableMap

implements LinkedHashMap TreeMap


extends
Map Interface
<<interface>>
Map

<<interface>>
SortedMap

<<interface>>
Hashmap
NavigableMap

implements LinkedHashMap TreeMap


extends
Map Interface
<<interface>>
Map

<<interface>>
SortedMap

<<interface>>
Hashmap
NavigableMap

implements LinkedHashMap TreeMap


extends
Map Interface
<<interface>>
Map

<<interface>>
SortedMap

<<interface>>
Hashmap
NavigableMap

implements LinkedHashMap TreeMap


extends
Map Interface
<<interface>>
Map

<<interface>>
SortedMap

<<interface>>
Hashmap
NavigableMap

implements LinkedHashMap TreeMap


extends
Map Interface
<<interface>>
Map

<<interface>>
SortedMap

<<interface>>
Hashmap
NavigableMap

implements LinkedHashMap TreeMap


extends
Map Interface
<<interface>>
Map

<<interface>>
SortedMap

<<interface>>
Hashmap
NavigableMap

implements LinkedHashMap TreeMap


extends
Generics
List myList = new ArrayList (100);

Map myMap = new HashMap(100);


Generics
List<String> myList = new ArrayList<String>(100);
Generics
List<String> myList = new ArrayList<String>(100);
Generics
List<String> myList = new ArrayList<String>(100);

Map<VIN, Car> myMap = new HashMap<VIN, Car>(100);


Generics
List<String> myList = new ArrayList<String>(100);

Map<VIN, Car> myMap = new HashMap<VIN, Car>(100);


Generics
List<String> myList = new ArrayList<String>(100);

Map<VIN, Car> myMap = new HashMap<VIN, Car>(100);


Generics
Collection<String> myList = new ArrayList<String>(100);

Map<VIN, Car> myMap = new HashMap<VIN, Car>(100);


Generics
Collection<String> myList = new ArrayList<String>(100);

Map<VIN, Car> myMap = new HashMap<VIN, Car>(100);


Generics
Collection<String> myList = new ArrayList<String>(100);

Map<VIN, Car> myMap = new HashMap<VIN, Car>(100);


Generics
Collection<String> myList = new ArrayList<String>(100);

Map<VIN, Car> myMap = new HashMap<VIN, Car>(100);


Generics
Collection<String> myList = new ArrayList<String>(100);

Map<VIN, Car> myMap = new HashMap<VIN, Car>(100);


Generics
Collection<String> myList = new ArrayList<String>(100);

Map<VIN, Car> myMap = new HashMap<VIN, Car>(100);


Generics
Collection<String> myList = new ArrayList<String>(100);

Map<VIN, Car> myMap = new HashMap<VIN, Car>(100);


Generics
Collection<String> myList = new ArrayList<String>(100);

Map<VIN, Car> myMap = new HashMap<VIN, Car>(100);


Generics
Collection<String> myList = new ArrayList<String>(100);

Map<VIN, Car> myMap = new HashMap<VIN, Car>(100);


Generics
Collection<String> myList = new ArrayList<String>(100);

Map<VIN, Car> myMap = new HashMap<VIN, Car>(100);


Generics
Collection<String> myList = new ArrayList<>(100);

Map<VIN, Car> myMap = new HashMap<>(100);


Generics
Collection<String> myList = new ArrayList<>(100);

Map<VIN, Car> myMap = new HashMap<>(100);


Generics
Collection<String> myList = new ArrayList<>(100);

Map<VIN, Car> myMap = new HashMap<>(100);


Generics
Collection<String> myList = new ArrayList<>(100);

Map<VIN, Car> myMap = new HashMap<>(100);


Generics
public interface MyInterface<E,T> {

E read()

void process(T o1, T o2)

}
Generics
public interface MyInterface<E,T> {

E read()

void process(T o1, T o2)

}
Generics
public interface MyInterface<E,T> {

E read()

void process(T o1, T o2)

}
Utility Interfaces

• java.util.Iterator

• java.lang.Iterable

• java.lang.Comparable

• java.util.Comparator
Utility Interfaces

• java.util.Iterator

• java.lang.Iterable

• java.lang.Comparable

• java.util.Comparator
Utility Interfaces

• java.util.Iterator

• java.lang.Iterable

• java.lang.Comparable

• java.util.Comparator
Utility Interfaces

• java.util.Iterator

• java.lang.Iterable

• java.lang.Comparable

• java.util.Comparator
java.util.Iterator

• boolean hasNext();

• E next();

• void remove();
java.util.Iterator

• boolean hasNext();

• E next();

• void remove();
java.util.Iterator

• boolean hasNext();

• E next();

• void remove();
java.util.Iterator

• boolean hasNext();

• E next();

• void remove();
java.lang.Iterable

• Iterator<T> iterator()
java.lang.Iterable

• Iterator<T> iterator()
java.lang.Iterable

• Iterator<T> iterator()
java.lang.Iterable

• Iterator<T> iterator()
java.lang.Comparable

int compareTo(T o)
java.lang.Comparable

int compareTo(T o)
java.lang.Comparable

int compareTo(T o)
java.lang.Comparable

int compareTo(T o)
java.lang.Comparable

Return a negative integer if the object is less than the given method argument,
zero if the object is equal to the given method argument and a positive integer
if the object is greater than the given method argument.
java.lang.Comparable

Return a negative integer if the object is less than the given method argument,
zero if the object is equal to the given method argument and a positive integer
if the object is greater than the given method argument.
java.lang.Comparable

Return a negative integer if the object is less than the given method argument,
zero if the object is equal to the given method argument and a positive integer
if the object is greater than the given method argument.
java.lang.Comparable

Return a negative integer if the object is less than the given method argument,
zero if the object is equal to the given method argument and a positive integer
if the object is greater than the given method argument.
java.util.Comparator

int compare(T o1, T o2)


java.util.Comparator

int compare(T o1, T o2)


java.util.Comparator

int compare(T o1, T o2)


java.util.Comparator

Return a negative integer if the first argument is less than the second argument,
zero if both arguments are equal and a positive integer if the first argument is
greater than the second
Utility classes
Utility classes

• java.util.Collections
Utility classes

• java.util.Collections

• java.util.Arrays
Copyright © 2015
Marcus Biel
All rights reserved

You might also like