🧪 Practice Question Set
🔹 Level 1: Basics
1. Create a HashMap of employee names and their IDs. Print all key-value pairs.
2. Add a duplicate key in HashMap. What happens to the value?
3. Create a LinkedHashMap and observe the insertion order.
4. Create a TreeMap and insert keys in random order. Print it.
5. Check if HashMap, LinkedHashMap, and TreeMap allow null as key or value.
6. Iterate over a HashMap using keySet(), entrySet(), and forEach().
🔹 Level 2: Intermediate Use Cases
7. Write a program to count the frequency of characters in a string using
HashMap.
8. Maintain insertion order of words in a sentence while counting frequency (use
LinkedHashMap).
9. Sort a map by keys using TreeMap.
10.Write a program to merge two HashMaps. If key exists, sum the values.
11.Write a method that finds the first non-repeating character in a string using
LinkedHashMap.
12.Write a method to remove all entries with null keys or values from a HashMap.
13.Check if two maps are equal (contain same key-value pairs).
🔹 Level 3: Coding Scenarios & Custom Sorting
14.Store and sort students by roll number using TreeMap<Integer, Student>.
15.Use TreeMap with a custom comparator to sort strings in reverse order.
16.Group words in a list by their starting letter using HashMap<Character,
List<String>>.
17.Sort a HashMap by values (ascending and descending).
18.Write a program to find the highest occurring entry in a map.
19.Use TreeMap to implement a simple leaderboard (key = score, value = player
name).
20.Detect duplicate values in a map (e.g., two keys pointing to the same value).