Java: Collection, Map

By Xah Lee. Date:

This page teachs you about Java's Collection, Map, that's other language's list, array, vector, dictionary, hash table.

What's 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's 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: What's Interface in Java?.

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

Java

  1. Install
  2. javac java jar javadoc

Java Basics

  1. Print String
  2. Strings
  3. Power Function
  4. Java Types and Type Conversion
  5. Function
  6. Arrays

Class, Inheritance

  1. extends
  2. Constructor
  3. Constructor Return Type
  4. Extending a Class that has Explicit Constructors
  5. static
  6. this
  7. super
  8. Access Specifiers

Abstract class, Interface

  1. abstract
  2. Interface

Package

  1. Package

Misc

  1. Collection, Map
  2. Read/Write File
  3. Convert File Encoding
  4. Complex Numbers in Java
  5. Unicode
  6. Number Literals