Java Collections

Java collections framework is a unified architecture for representing and manipulating collections. All collections frameworks contain the following:

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, i.e., Classes: 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.

In addition to collections, the framework defines several map interfaces and classes. Maps store key/value pairs. Although maps are not collections in the proper use of the term, but they are fully integrated with collections.

Related Tags

Tutorials

Java Collections

Java List Initialization in One Line: List.of and ArrayList

Initialize a Java List in one line with List.of() for an unmodifiable list, or new ArrayList<>(List.of(…)) when the list changes later. Compare Arrays.asList(), Stream.toList(), Collections and Guava by mutability and null support.

Java UnsupportedOperationException: Causes and How to Fix

java.lang.UnsupportedOperationException means the code tried to change a collection that cannot be changed, such as one from Arrays.asList(), List.of() or Collections.unmodifiableMap(). Copy the data into an ArrayList or HashMap to fix it.

Java Map: HashMap vs LinkedHashMap vs TreeMap and More

A Java Map stores unique keys with one value each. Quick put/get/merge/computeIfAbsent examples, a comparison of HashMap, LinkedHashMap, TreeMap, ConcurrentHashMap, EnumMap, Hashtable and Map.of(), and all our Map tutorials grouped by topic.

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.