![]() |
Intro | Lists | Sets | Queues and Deques | Conclusion |
Collectables Summary
Summary Diagram
Java Collections Homework (due the Wednesday After Spring break)
Objectives
- Practice using List, Set, and Deque
- Understand when and why to use each
- Apply key methods from each collection type
- Practice iteration and conditional logic with collections
Part 1: Working with Lists
Task:
Create a method that takes a List
Requirements:
- Use ArrayList
- Use add, get, and size
- Use a loop (not streams)
Part 2: Working with Sets
Task:
Create a method that takes two Set
Requirements:
- Use HashSet
- Use contains, add, and iteration
- Final result should have no duplicates
Part 3: Working with Deques
Task:
Simulate a line of customers using a Deque
- Add 3 customers to the end
- Add 1 customer to the front (VIP)
- Remove the customer at the front
- Show the current front and back of the line
- Print the size of the line
Requirements:
- Use ArrayDeque
- Use addFirst, addLast, removeFirst, peekFirst, peekLast, and size
Challenge Question (Bonus +0.01)
Question:
You need to store a collection of student IDs where:
- Order doesn’t matter
- You must prevent duplicates
- You often need to check if an ID exists
Which collection type would be most efficient to use and why?