Introduction to Java · Introduction to Java Programming

Util Package

Watch lectures

Util Package

1. What It Is (beginner)

java.util = toolbox of everyday classes: Scanner (input), ArrayList (list), HashMap (dictionary), Random, Date, Collections. Import it to use 90% beginner programs.

2. Most-Used Classes (exam list)

Class One-line use Example
Scanner keyboard input new Scanner(System.in)
ArrayList resizable array list.add("hi")
HashMap key→value map.put("id", 101)
Random random numbers new Random().nextInt(100)
Arrays array helpers Arrays.sort(arr)
Collections list helpers Collections.sort(list)
Date / LocalDate dates LocalDate.now()

3. Code — Toolbox Demo

import java.util.*; // star imports whole toolbox (fine for beginners)
public class Tool {
    public static void main(String[] args) {
        ArrayList<String> names = new ArrayList<>();
        names.add("Asha"); names.add("Ravi");
        Collections.sort(names); // [Asha, Ravi]
        Random r = new Random();
        System.out.println(names + " lucky=" + r.nextInt(100));
        HashMap<String,Integer> marks = new HashMap<>();
        marks.put("Asha", 87);
        System.out.println(marks.get("Asha")); // 87
    }
}

4. Import Rules

  • java.lang auto (no import). java.util needs import java.util.Scanner; (one) or import java.util.*; (all — beginners ok, pros prefer single).
  • Wrong import → cannot find symbol ERROR.

5. Exam Points

  • List 5 util classes + use — 5 marks, frequent.
  • Import syntax (* vs single) — 2-3 marks, frequent.
Student FinanceWeb Platform

Pocketly — Personal Finance for Students

Keep your hostel and college expenses under control. Track accounts, log spending in seconds, and stay within your monthly budget.

← All Introduction to Java Programming modules