Introduction to java.util
The java.util package is arguably the most extensively used package in the Java ecosystem (after java.lang). It provides a massive collection of utility classes and interfaces that solve common programming problems, primarily focused on Data Structures and Algorithms.
The Collections Framework
Before the Collections Framework (introduced in JDK 1.2), the standard methods for grouping Java objects (or collections) were Arrays, Vectors, and Hashtables. All of these collections had no common interface.
The Random Class
The java.util.Random class is used to generate a stream of pseudorandom numbers.
The List Interface
The List interface extends the Collection interface. It represents an ordered collection of elements, meaning it maintains the insertion order. Furthermore, unlike Sets, Lists allow duplicate elements.
The UUID Class
The java.util.UUID class represents an immutable Universally Unique Identifier (UUID).
The Set Interface
The Set interface extends the Collection interface. It represents an unordered collection of elements that does not allow duplicate elements. It is essentially a programmatic implementation of the mathematical set abstraction.
The StringTokenizer Class
The java.util.StringTokenizer class allows an application to break a string into individual pieces, called tokens.
The Properties Class
The java.util.Properties class is a subclass of Hashtable. It is used to maintain a persistent set of properties, where both the keys and the values are exclusively String objects.
The Queue Interface
The Queue interface extends the Collection interface. It is used to hold elements about to be processed and typically orders elements in a FIFO (First-In-First-Out) manner.
The Map Interface
The Map interface is not a subtype of the Collection interface. Therefore, its behavior is slightly different from the others.
Timer & TimerTask
The java.util.Timer and java.util.TimerTask classes provide a built-in mechanism for developers to schedule tasks to run in a background thread. You can schedule a task to run once at a specific time, or repeatedly at a regular interval.
The Collections Class
The Java Collections Framework does not only provide data structures (interfaces and implementation classes). It also provides a highly powerful utility class named java.util.Collections.
The Scanner Class
The java.util.Scanner class is one of the most frequently used classes by beginners learning Java. It provides a simple and intuitive way to read input from various sources, most commonly from the user via the console.
Date and Calendar
Before the introduction of the modern java.time package in Java 8, developers primarily relied on the java.util.Date and java.util.Calendar classes to handle dates and times.