- Java Collections Framework: interfaces + classes that implement common data structures and algorithms (java.util).
- Three parts: interfaces, implementations (classes), algorithms (static methods in Collections).
- Core interfaces: Collection, Set (no duplicates), List (ordered, duplicates allowed), Queue, Map (key → value).
🎯 How this can come up · 1 question
Which collection type does NOT allow duplicate elements?
Correct: Set.
- Map is NOT a Collection: it stores key–value pairs.
🎯 How this can come up · 1 question
Map extends the Collection interface.
False.
- List: ordered, duplicates allowed, zero-based indexes (ArrayList, LinkedList).
- ArrayList: like an array but resizes automatically; holds objects only (Integer, not int).
🎯 How this can come up · 1 question
An ArrayList<int> declaration:
Correct: Does not compile (use ArrayList<Integer>).
- Methods: add, add(index, e), get, set, remove, size, contains, indexOf, clear, isEmpty.
🎯 How this can come up · 1 question
Which returns the number of elements in an ArrayList list?
Correct: list.size().
- Iterator: hasNext(), next(), remove(): the safe way to remove while iterating.
🎯 How this can come up · 1 question
Removing elements from a list inside a for-each loop is safe.
False. Use an Iterator’s remove() (else ConcurrentModificationException).
- Java 7 diamond: List<String> list = new ArrayList<>();
- Collections.sort(list) sorts a List (natural order or with a Comparator).
- Collections.binarySearch(sortedList, key) returns the index, or −(insertion point) − 1 if absent. The list must be sorted first.
🎯 How this can come up · 1 question
Collections.binarySearch requires the list to be:
Correct: Sorted.
No slides match this filter.