Stage 1 · Lesson 7 of 9
Arrays, ArrayList and HashMap
Java have a fixed length, set when you create them, such as int[] scores = new int[5]. So most code uses the collections instead. An ArrayList grows as you add to it, with add, get, set, remove and size.
A maps keys to values with put, get, containsKey and getOrDefault, and get returns null for a missing key. The angle brackets in ArrayList<String> or HashMap<String, Integer> are . They tell the compiler what the collection holds.
They only accept object types, so you write ArrayList<Integer>, not ArrayList<int>, and Java wraps the numbers for you (this is called boxing). A stores unique items. Declare variables with the general interface type, as in List<String> names = new ArrayList<>(), to keep your code flexible.
A question to check yourself, an AI practice session and 4 cheat sheet entries come when you add the roadmap to your account. Add it
Resources for this stage
Start with· follow one of these
- CourseFreeJava Programming MOOC
University of Helsinki · Beginner
Free Helsinki course with hundreds of auto-tested exercises; parts 1 to 8 cover this stage
- GuideFreeDev.java: Learn Java
Oracle · Beginner
Official tutorials from the Java team: read the language basics path next to the MOOC