0% found this document useful (0 votes)
4 views2 pages

9.map in Java

The document contains a practice question set divided into three levels: Basics, Intermediate Use Cases, and Coding Scenarios & Custom Sorting. Each level includes programming tasks related to HashMap, LinkedHashMap, and TreeMap, focusing on operations like insertion, frequency counting, sorting, and handling duplicates. The exercises are designed to enhance understanding and application of these data structures in various scenarios.

Uploaded by

shivamverma63970
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

9.map in Java

The document contains a practice question set divided into three levels: Basics, Intermediate Use Cases, and Coding Scenarios & Custom Sorting. Each level includes programming tasks related to HashMap, LinkedHashMap, and TreeMap, focusing on operations like insertion, frequency counting, sorting, and handling duplicates. The exercises are designed to enhance understanding and application of these data structures in various scenarios.

Uploaded by

shivamverma63970
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

🧪 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).

You might also like