Work with fixed-size arrays and dynamic collections like ArrayList and HashMap.
1public class ArrayDemo {2 public static void main(String[] args) {3 // Declaration and initialization4 int[] numbers = {10, 20, 30, 40, 50};5 6 // Access by index7 System.out.println(numbers[0]); // 108 System.out.println(numbers.length); // 59 10 // Loop through array11 for (int num : numbers) {12 System.out.print(num + " ");13 }14 // Output: 10 20 30 40 5015 }16}10 5 10 20 30 40 50
1import java.util.ArrayList;2import java.util.HashMap;3 4public class CollectionsDemo {5 public static void main(String[] args) {6 // ArrayList7 ArrayList<String> skills = new ArrayList<>();8 skills.add("Java");9 skills.add("Python");10 skills.add("SQL");11 System.out.println(skills); // [Java, Python, SQL]12 13 // HashMap14 HashMap<String, Integer> scores = new HashMap<>();15 scores.put("Alice", 95);16 scores.put("Bob", 88);17 System.out.println(scores.get("Alice")); // 9518 }19}[Java, Python, SQL] 95