Java: Collection and Map

By Xah Lee. Date: . Last updated: .

What is Collection, Map?

In Java, “collection” is basically a datatype that's list-like. In other languages called {list, array, vector, …}.

In Java, “map” is basically a datatype that's a set of key/value pairs. In other languages called {hash table, dictionary, map, associative list}.

In Java, the collection and map are actually Java Interfaces.

Note: “collection” and “map” are different interfaces, but sometimes the word “collection” informally mean both.

What is Interface?

A Java Interface defines a list of methods. Then, any Class can declare to implement that interface.

If a class C implements interface X and Y and Z, then it effectively means the C has all methods declared in X, Y, Z.

Java Interface can be inherited. That is, a interface Y can “extend” another interface X. So that, two interfaces may have a parent-child relationship. The parent interface is called “superinterface”. The child interface is called “subinterface”.

When a interface extends another, it basically modifies/adds more methods.

The full names are:

If you want to know how to actually write code to define interface, or for a class to implement interface, see: Java: Interface .

Sample methods of Collection Interface

The collection interface has methods like the following.

Sample Methods of Map Interface

A map interface has methods similar to the collection interface, but also has methods that get value of a given key. Remeber, a “map” is basically a list of key/value pairs.

Some sample methods of map interface:

Children of Collection Interface

The Collection interface has the following children. Each of these interface is more specialized list-like type. (don't forget, these are all interfaces.)

Children of Map Interface

The Map interface has the following children:

Implementations of Collection Interface

The following are classes that implements the collection interface.

Implementations of Map Interface