Unit 9 ยท Robust data-driven programs
Path and Files.Use ArrayList for ordered, resizable data and HashMap for key-to-value lookup. Generics document the element type and prevent many casts.
List<String> topics = new ArrayList<>();
topics.add("classes");
topics.add("testing");
Map<String, Integer> minutes = new HashMap<>();
minutes.put("classes", 45);
try {
List<String> lines = Files.readAllLines(Path.of("study.txt"));
System.out.println(lines.size());
} catch (IOException error) {
System.err.println("Could not read study file: " + error.getMessage());
}Catch the narrowest exception you can handle. Never use an empty catch block. Preserve useful context in an error message or rethrow with a cause.
Map<String,Integer>.IOException force you to do?Mastery task: Build a command-line study log that loads entries, adds a session, and saves the updated data.