1. Basic ArrayList Manipulation
Problem:
Create a program to manage a bookstore inventory using ArrayList<Book>
. Each Book
has a title (String) and price (double).
Add 5 books
Remove the cheapest book
Print the remaining books sorted by price
2. HashMap for Employee Database
Problem:
Build an employee ID lookup system using HashMap<Integer, Employee>
.
Add employees with ID as key
Allow searching by ID
Print all employees in alphabetical order
3. HashSet for Social Media Tags
Problem:
Implement a unique hashtag tracker for posts using HashSet<String>
.
Add tags like "#Java", "#Programming"
Prevent duplicates
Show trending tags in alphabetical order
4. PriorityQueue for Airport Security
Problem:
Simulate an airport security line where:
First-class passengers (
priority=1
) go firstEconomy passengers (
priority=3
) go lastUse
PriorityQueue<Passenger>
5. LinkedList for Browser History
Problem:
Create a browser history with LinkedList<String>
that:
Stores visited URLs
Allows "back" and "forward" navigation
Limits history to 10 entries
6. TreeMap for Product Catalog
Problem:
Build a sorted product catalog using TreeMap<String, Double>
where:
Key = Product name
Value = Price
Display products alphabetically
Find the most expensive product
7. Stack for Undo/Redo System
Problem:
Implement text editor undo/redo using two Stack<String>
:
undoStack
stores document statesredoStack
stores undone states
8. ArrayDeque for Ticket Booking
Problem:
Simulate a concert ticket booking system with ArrayDeque<String>
:
First-come-first-served queue
Allow VIPs to cut in line (add to front)
9. Custom Comparator for Employee Sorting
Problem:
Sort a List<Employee>
:
First by department (ascending)
Then by salary (descending)
10. WeakHashMap for Cache System
Problem:
Create a memory-sensitive cache using WeakHashMap<String, Image>
:
Automatically removes entries when memory is low
Ideal for storing temporary image thumbnails
Key Concepts Tested
Question | Collections Used | Core Concept |
---|---|---|
1 | ArrayList | Sorting, removal |
2 | HashMap | Key-value lookup |
3 | HashSet | Uniqueness |
4 | PriorityQueue | Custom ordering |
5 | LinkedList | Sequential access |
6 | TreeMap | Auto-sorting |
7 | Stack | LIFO operations |
8 | ArrayDeque | FIFO + priority |
9 | List | Custom Comparator |
10 | WeakHashMap | Memory management |
No comments:
Post a Comment