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
Type | Description |
---|---|
Interfaces | These 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. |
Implementations | These are the concrete implementations of the collection interfaces. In essence, they are reusable data structures. |
Algorithms | These 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 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
- Hashtable Example
Simple example shows you step by step how to use Hashtable - HashMap Example
Simple example shows you step by step how to use HashMap - TreeMap Example
Simple example shows you step by step how to use TreeMap to sort a collection - EnumMap Example
Simple example shows you step by step how to use EnumMap for type-safety and speed of finite list of elements - WeakHashMap Example
Simple example shows you step by step how to use WeakHashMap - LinkedHashMap Example
Simple example shows you step by step how to use LinkedHashMap - Performance Comparison HashMap vs Hashtable vs TreeMap
Performance Comparison – Performance Comparison HashMap vs Hashtable vs TreeMap Benchmark Test
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
- Stack Example
Simple example shows you step by step how to use Stack - Vector Example
Simple example shows you step by step how to use Vector - LinkedList Example
Simple example shows you step by step how to use LinkedList - ArrayList Example
Simple example shows you step by step how to use ArrayList - Performance Comparison between the four list implementations
Performance Comparison of ArrayList, LinkedList, Vector, and Stack - Performance Comparison ArrayList vs LinkedList
Performance Comparison – ArrayList vs LinkedList
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
- BitSet Example
Simple example shows you step by step how to use BitSet - EnumSet Example
Simple example shows you step by step how to use EnumSet - HashSet Example
Simple example shows you step by step how to use HashSet - TreeSet Example
Simple example shows you step by step how to use TreeSet - LinkedHashSet Example
Simple example shows you step by step how to use LinkedHashSet
Please Share Us on Social Media






Leave a Reply