Java Collections Tutorial

This Java Collections Tutorial series explains the usage of the Java collections framework including Lists, Maps and Sets. It will discuss the major java collection classes in detail and give examples of each with vivid and well tested Java programs.

When Java was first released it only included a limited subset of useful data structures: Vector, Stack, HashTable, Dictionary, BitSet and the Enumeration interface. However, when Java 2 rolled out to the masses it included a full set of data structures. The Java development team set out with the following criteria:

  • Library needed to be small and easy to learn
  • Benefit of generic algorithms
  • Legacy classes needed to fit into the new framework

The java collections framework separates interfaces and their implementations. The collections framework also contains many concrete implementations that you may begin using immediately such as HashMap, LinkedList, ArrayList, HashSet and TreeSet.

Java 6 introduced additional enhancements to the collections framework with more emphasis on bidirectional access. We will touch more of these in later tutorials.

Collections Framework

TypeDescription
InterfacesThese are abstract data types that represent collections. Interfaces allow collections to be manipulated independently of the details of their representation. In object-oriented languages, interfaces generally form a hierarchy.
ImplementationsThese are the concrete implementations of the collection interfaces. In essence, they are reusable data structures.
AlgorithmsThese are the methods that perform useful computations, such as searching and sorting, on objects that implement collection interfaces. The algorithms are said to be polymorphic: that is, the same method can be used on many different implementations of the appropriate collection interface.

What are Collections

A collection contains a group of objects known as elements. Almost all collections in Java are derived from java.util.Collection interface. This interface defines the following basic operations like:

  • Adding element(s) to the collection
  • Removing element(s) from the collection
  • Obtaining the size of the collection
  • Iterating through the collection

java_collections

Java Collections Tutorial

In this Java Collections tutorial series, we will discuss all the interfaces and many of the concrete implementations of the Java Collections Framework (JCF) and give you an overview of the java collection classes. Although I will not concentrate on all the minute details of the java collection classes, I will try to touch base on the classes that implement the java.util.Map, java.util.List and java.util.Set interfaces and show you how to use each one.

Java Collections Framework Examples

Map Concrete Classes

In this Java Collection Tutorial series we concentrate on java.util.Map classes. The Map interface represents a mapping of a key and a value and include the following:

  • HashMap
  • HashTable
  • EnumMap
  • TreeMap
  • WeakHashMap
  • LinkedHashMap
  • IdentityHashMap

Java Collection Map Examples

List Concrete Classes

In this Java Collection Tutorial series we concentrate on java.util.List classes. The java.util.List interface is a subtype of the java.util.Collection interface and include the following:

  • Stack
  • Vector
  • ArrayList
  • LinkedList

Java Collection List Examples

Set Concrete Classes

In this Java Collection Tutorial series we concentrate on java.util.Set classes. The java.util.Set interface is a subtype of the java.util.Collection interface and include the following:

  • BitSet
  • EnumSet
  • HashSet
  • TreeSet
  • LinkedHashSet

Java Collection Set Examples

Please Share Us on Social Media

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Leave a Reply

Your email address will not be published. Required fields are marked *