
The Collections API - java.util.ArrayList and java.util.HashMap
The java.util package contains a great assortment of data structures. Only two will be covered here, but we will mention the others from time to time. Some JVM languages use their own variations of these classes that offer additional functionality, but most languages work with the classes discussed here for maximal compatibility with both Java and JVM platforms in general.
Many languages support a technique called generics, that limits the types of objects that an object can use. In the case of Collection classes, these limit the objects that can be stored inside a collection class. As many languages have different notation rules for generics, this topic will be explained for each language separately and ignored for now. Clojure is one example of a language that is covered in this book that currently does not support generics at all.
It is worth noting that the Collection classes only work with objects. When primitive values are used, they are autoboxed into the object and vice versa; this is applicable if the used JVM language could use primitive values. Autoboxing was discussed when we talked about primitive value wrapper classes earlier.
The two Collections classes that we will cover are:
- java.util.ArrayList (a list class, backed internally by an array)
- java.util.HashMap (a container for key/value combinations)