Java Collections Framework Flashcards
7 cards from real SCJP practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Java Collections Framework flashcards as text
What is the difference between `HashSet` and `LinkedHashSet`?
Answer: LinkedHashSet maintains insertion order; HashSet does not
LinkedHashSet uses a linked list internally to maintain the order in which elements were inserted, while HashSet has no ordering guarantee.
Which method of the `Collections` class returns an unmodifiable view of a specified list?
Answer: Collections.unmodifiableList(list)
Collections.unmodifiableList() wraps a list in a view that throws UnsupportedOperationException on any mutating operation.
What does the `NavigableMap` interface add over `SortedMap`?
Answer: Methods like floorKey(), ceilingKey(), higherKey(), and lowerKey()
NavigableMap extends SortedMap with navigation methods that return the closest matches for given search targets, such as floor, ceiling, higher, and lower.
Which of the following is NOT a characteristic of `ConcurrentHashMap`?
Answer: It allows null keys
ConcurrentHashMap does not permit null keys or null values, unlike HashMap which allows one null key.
What is the time complexity of `contains()` on a `HashSet` in the average case?
Answer: O(1)
HashSet.contains() is O(1) on average because it computes the hash code to directly locate the bucket, then checks equality.
Given `TreeSet ts = new TreeSet<>(); ts.add(5); ts.add(1); ts.add(3);`, what does `ts.first()` return?
Answer: 1
TreeSet stores elements in ascending natural order, so first() returns the smallest element, which is 1.
Which statement accurately describes `Collections.sort()` for a `List` where T does not implement `Comparable`?
Answer: A ClassCastException is thrown at runtime
If T does not implement Comparable and no Comparator is supplied, Collections.sort() throws a ClassCastException at runtime when it tries to cast elements to Comparable.
How this page was made: written with AI tools and published by Nathan Beja, founder of Practice Test Geeks, who is responsible for its content. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Not reviewed by a subject-matter expert. Editorial policy