Notes

Java Data Types

Daniel Weibel
Created 10 Nov 2017
Last updated 13 Nov 2017

Set

Three general-purpose implementations of the Set interface:

Use HashSet unless you need the elements to be in a certain fixed order.

List

Tutorial on List implementations.

General-purpose List implementations:

Map

Note that Map does not extend Collection like all the other interafaces in this document.

  • Map interface

Tutorial on Map implementations

General-purpose Map implementations:

HashMap vs. Hashtable

HashMap is a member of the Java Collections Framework.

Hashtable is an older legacy class that has been retrofitted to fit in the Java Collections Framework.

The differences between HashMap and Hashtable are:

  • HashMap permits a null key and null values, whereas Hashtable permits only non-null keys and values.
  • HashMap is not syncrhonised, whereas Hashtable is synchronised (that is, thread-safe).

Hashtable can be regarded as obsolete. If you need a synchronised HashMap, it’s better to use ConcurrentHashMap than Hashtable (see here).

Queue

Queue interface.

General-purpose implementations of Queue:

Deque

Stands for double-ended queue.

Deque interface.

General-purpose implementations:

The Java Collections Framework

  • Guide on Oracle
  • All the interfaces and classes that are part of the Collections Framework are listed here
General-purpose Implementations
Interfaces Hash table Implementations Resizable array Implementations Tree Implementations Linked list Implementations Hash table + Linked list Implementations
Set HashSet   TreeSet   LinkedHashSet
List   ArrayList   LinkedList  
Queue   PriorityQueue   LinkedList  
Deque   ArrayDeque   LinkedList  
Map HashMap   TreeMap   LinkedHashMap

All the above interfaces (except Map) implement the Collection interface.

The Collections class contains static methods that operate on objects implementing the above interfaces.