Tutorials Courses Interview Prep (100 Q&A) AI Tools (50) Developer Tools (50) Tracks Pricing Plans Blog & Articles Contact Us
Core Java & Object-Oriented Architecture 20 mins read Free Lesson

Java Collections Framework & Exception Handling

Work with ArrayList, HashMap, HashSet, and handle runtime exceptions using try-catch-finally and try-with-resources.

Java Collections & Error Handling

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CollectionsDemo {
    public static void main(String[] args) {
        // List Interface & ArrayList
        List<String> tracks = new ArrayList<>();
        tracks.add("Java");
        tracks.add("Spring Boot");

        // Key-Value Map
        Map<String, Integer> scores = new HashMap<>();
        scores.put("Java Quiz", 95);

        // Robust Exception Handling
        try {
            int result = 100 / 0;
        } catch (ArithmeticException e) {
            System.err.println("Calculation error: " + e.getMessage());
        } finally {
            System.out.println("Cleanup executed.");
        }
    }
}