Core Java


Copyright © Cay S. Horstmann 2016

Understand the benefit of separate collection classes and interfaces

Collection Interfaces

Collection Classes

Become familiar with the types in the collections framework

Fundamental Interfaces

Using Iterators

More about Iterators

Useful Collection Methods

int size()
boolean isEmpty()
boolean contains(Object obj)
boolean containsAll(Collection<?> c)
boolean equals(Object other)
boolean addAll(Collection<? extends E> from)
boolean remove(Object obj)
boolean removeAll(Collection<?> c)
boolean removeIf(Predicate<? super E> filter)
void clear()
boolean retainAll(Collection<?> c)
Object[] toArray()
<T> T[] toArray(T[] arrayToFill)

Interfaces in the Collection Framework


Concrete Collections

ArrayList An indexed sequence that grows and shrinks dynamically
LinkedList An ordered sequence that allows efficient insertion and removal at any location
ArrayDeque A double-ended queue that is implemented as a circular array
HashSet An unordered collection that rejects duplicates
TreeSet A sorted set
EnumSet A set of enumerated type values
LinkedHashSet A set that remembers the order in which elements were inserted
PriorityQueue A collection that allows efficient removal of the smallest element
HashMap A data structure that stores key/value associations
TreeMap A map in which the keys are sorted
EnumMap A map in which the keys belong to an enumerated type
LinkedHashMap A map that remembers the order in which entries were added
WeakHashMap A map with values that can be reclaimed by the garbage collector if they are not used elsewhere
IdentityHashMap A map with keys that are compared by ==, not equals

Collection Classes

Work with linked lists and array lists

Why Linked Lists?

Linked Lists

Concurrent Modifications


Other Lists

Work with hash sets and sorted sets

Hash Sets


Tree Sets


Work with queues, deques, and priority queues

Queues, Deques, and Priority Queues


Use maps to organize key/value pairs



Updating Map Entries

Map Views

Linked Hash Maps

Understand collection wrappers and views


Restricted Views

Use common algorithms with collections

Common Algorithms

Bulk Operations

Converting between Collections and Arrays


Be able to use collections from old versions of Java

Legacy Collections