Last Updated: December 6, 2025
32 quizzes
Add an element to the end of an ArrayList of tasks
tasks.("Deploy");Click an option to fill the blank:
Retrieve the value for a username key from a HashMap
Integer count = loginAttempts.("alice");Click an option to fill the blank:
Add an element to the front of an ArrayDeque used as a stack
history.(url);Click an option to fill the blank:
Which core interfaces are the main roots of the Java Collections Framework?
Which statement about the Collection interface is true?
You need an ordered collection that allows duplicates and supports fast random access by index. Which type fits best?
When is LinkedList typically preferred over ArrayList?
Which statement about Vector is accurate?
Which Java collection is best suited to check membership without allowing duplicates and without caring about order?
Which Set implementation maintains elements in sorted order?
Which Queue method retrieves and removes the head, returning null if the queue is empty?
You need a Map that keeps keys sorted by their natural order. Which implementation should you choose?
Which concurrent collection is most suitable as a thread-safe replacement for HashMap?
Which utility class provides static methods like sort, reverse, and shuffle for collections?
Which interface should a class implement to define its natural ordering used by Collections.sort(list)?
Order the steps to use an Iterator to safely remove specific elements from a List.
Drag and drop to reorder, or use the arrows.
Order the steps to use a TreeMap with a custom Comparator.
Drag and drop to reorder, or use the arrows.
What is the output of this code using LinkedHashSet?
1import java.util.*;
2public class Test {
3 public static void main(String[] args) {
4 Set<String> ids = new LinkedHashSet<>();
5 ids.add("A");
6 ids.add("B");
7 ids.add("A");
8 System.out.println(ids.size());
9 }
10}What is the output of this code using PriorityQueue?
1import java.util.*;
2public class TestPQ {
3 public static void main(String[] args) {
4 PriorityQueue<Integer> q = new PriorityQueue<>();
5 q.add(10);
6 q.add(5);
7 q.add(7);
8 System.out.println(q.poll());
9 }
10}What is the output of this TreeSet example?
1import java.util.*;
2public class TestTS {
3 public static void main(String[] args) {
4 Set<String> set = new TreeSet<>();
5 set.add("dog");
6 set.add("ant");
7 set.add("cat");
8 System.out.println(((TreeSet<String>) set).first());
9 }
10}What does this code print using LinkedHashMap?
1import java.util.*;
2public class TestLHM {
3 public static void main(String[] args) {
4 Map<String,Integer> map = new LinkedHashMap<>();
5 map.put("x", 1);
6 map.put("y", 2);
7 map.put("x", 3);
8 System.out.println(map.get("x"));
9 }
10}What is printed by this code using Collections and Comparable?
1import java.util.*;
2class Job implements Comparable<Job> {
3 int priority;
4 Job(int p) { this.priority = p; }
5 public int compareTo(Job o) { return Integer.compare(this.priority, o.priority); }
6}
7public class TestJobs {
8 public static void main(String[] args) {
9 List<Job> jobs = new ArrayList<>();
10 jobs.add(new Job(3));
11 jobs.add(new Job(1));
12 Collections.sort(jobs);
13 System.out.println(jobs.get(0).priority);
14 }
15}Find the bug in this code that uses HashSet for unique emails.
Click on the line(s) that contain the bug.
import java.util.*;public class EmailStore { private Set<String> emails = new HashSet<>(); public boolean addEmail(String email) { emails.add(email); return emails.contains(email) == false; }}Find the bug in this TreeMap code that should sort users by score descending.
Click on the line(s) that contain the bug.
import java.util.*;public class Scores { private Map<Integer, String> users = new TreeMap<>(); public Scores() { users = new TreeMap<>(); } public void add(int score, String name) { users.put(score, name); }}Match each collection implementation to its key characteristic.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Match each Map implementation to its behavior.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Complete the code to create a thread-safe map of session tokens using the concurrent collections package.
import java.util.concurrent.;public class SessionStore { private <String, Long> sessions = new <>(); public void put(String token, long expiresAt) { sessions.(token, expiresAt); }}Click an option to fill blank 1:
Complete the code to sort a list of tasks by name using Collections and a Comparator.
import java.util.*;public class TaskSorter { public static void sortByName(List<String> tasks) { Collections.(tasks, Comparator.(String::)); }}Click an option to fill blank 1:
Complete the code to iterate through a List using a ListIterator and update an element.
import java.util.*;public class UpdateNames { public static void upperCaseFirst(List<String> names) { ListIterator<String> it = names.(); if (it.()) { String first = it.next(); it.(first.toUpperCase()); } }}Click an option to fill blank 1:
Complete the code to build a Deque-based Stack with ArrayDeque.
import java.util.*;public class BrowserStack { private Deque<String> history = new <>(); public void visit(String url) { history.(url); } public String back() { return history.(); }}Click an option to fill blank 1:
Click the line that can throw a ConcurrentModificationException when iterating a List.
Click on the line to select.
import java.util.*;public class Demo { public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("A"); list.add("B"); for (String s : list) { if (s.equals("A")) { list.remove(s); } } }}Click the line that causes a NullPointerException when using Map and get().
Click on the line to select.
import java.util.*;public class Demo2 { public static void main(String[] args) { Map<String, List<String>> tags = new HashMap<>(); List<String> list = tags.get("java"); list.add("collections"); System.out.println(list.size()); }}