Package java.util

The java.util package in Java is a versatile utility package encompassing numerous classes and interfaces designed for the various advanced programming tasks and it offers a broad range of the functionalities including data structures, input/output operations and many other commonly used utilities.

Example of java.util package:

Java




//Java program to demonstrate 'java.util package'
import java.util.ArrayList;
public class GFG {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("apple");
        list.add("banana");
        list.add("Mango");
        System.out.println("List: " + list);
    }
}


Output

List: [apple, banana, Mango]




Difference Between java.lang and java.util

Java Packages contain classes, interfaces, and sub-packages. The packages java.lang and java.util are two of the most commonly used packages in Java Standard Library. Both packages contain useful classes and utilities.

In this article, we will learn about java.lang and java.util package with examples and also the difference between these two packages.

Similar Reads

Package java.lang

The java.lang package in Java is a core package that includes the fundamental classes and features of Java language. It is automatically available in every Java program eliminating the need for explicit import statements....

Package java.util

...

Difference between java.lang and java.util

The java.util package in Java is a versatile utility package encompassing numerous classes and interfaces designed for the various advanced programming tasks and it offers a broad range of the functionalities including data structures, input/output operations and many other commonly used utilities....