Type common List operations on an ArrayList
Type common List operations on an ArrayList
Answer
List<String> list = new ArrayList<>(List.of("a", "b", "c")); list.add("d"); String second = list.get(1); // "b" list.remove("a"); System.out.println(list.size());
ArrayList wraps a resizable array. get(i) is O(1). We wrap List.of() in new ArrayList<>() to get a mutable copy.