Java.util Package in Java
The java.util package is one of the most widely used packages in the Java programming language. It provides a set of utility classes that support data structures, date and time manipulation, random number generation, event handling, and other commonly used functionalities in Java programs.
- Provides a rich Collection Framework (List, Set, Map) for data handling.
- Includes utility classes (Collections, Arrays) for sorting and searching.
- Offers Date, Calendar, and Random for time and random operations.
- Supports Properties for configuration management.
- Contains concurrent and legacy classes for compatibility.

Package Declaration
import java. util.*;
This single import statement allows access to all classes and interfaces inside the java.util package.
import java.util.*;
public class GFG{
public static void main(String[] args){
// Using ArrayList
List<String> names = new ArrayList<>();
names.add("Alice");
names.add("Bob");
names.add("Charlie");
// Using Collections utility class
Collections.sort(names);
System.out.println("Sorted Names: " + names);
// Simulated user input
String userName = "User";
System.out.println("Hello, " + userName + "!");
}
}
Output
Sorted Names: [Alice, Bob, Charlie] Hello, User!
Commonly Used Classes and Interfaces in java.util
| Category | Class / Interface | Description |
|---|---|---|
| Collection Framework | ArrayList, LinkedList, HashSet, TreeSet, HashMap, TreeMap | Implements data structures such as lists, sets, and maps. |
| Utility Classes | Collections, Arrays, Objects | Provide static methods for common tasks like sorting, searching, and null checks. |
| Iterator Interfaces | Iterator, ListIterator, Enumeration | Used to traverse elements in a collection. |
| Date and Time Classes | Date, Calendar, TimeZone, Timer, TimerTask | Handle and schedule date/time-related operations. |
| Random Number Generation | Random | Generates random numbers for simulations or games. |
| Tokenizing Strings | StringTokenizer | Splits strings into tokens based on delimiters. |
| User Input Handling | Scanner | Reads input from various sources like keyboard or files. |
| Properties and Resource Bundles | Properties, ResourceBundle | Used for configuration files and localization (internationalization). |
| Concurrent Collections | ConcurrentHashMap, CopyOnWriteArrayList, BlockingQueue | Thread-safe collections for multithreaded applications. |
Sub-packages of java.util
| Sub-Package | Purpose |
|---|---|
| java.util.concurrent | Contains thread-safe concurrent collection classes and synchronization utilities. |
| java.util.function | Provides functional interfaces for lambda expressions. |
| java.util.stream | Supports functional-style operations on streams of elements. |
| java.util.regex | Contains classes for regular expressions. |
java.util vs java.lang
| Feature | java.util Package | java.lang Package |
|---|---|---|
| Purpose | Provides utility classes such as collections, date/time, and random utilities. | Contains fundamental classes essential for Java language execution. |
| Common Classes | ArrayList, HashMap, Date, Collections, Scanner | String, Object, Math, System, Thread |
| Import Requirement | Must be explicitly imported in a program. | Imported automatically by default in every Java program. |
| Usage Type | Used for data structures, utilities, and general-purpose operations. | Used for basic language constructs and core functionality. |
| Package Type | Considered a utility package. | Considered a core package. |