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

Java HashMap Practice Assignment

This document is a Java HashMap practice assignment that includes a series of questions designed to enhance students' understanding of HashMap concepts, ranging from basic operations to more complex applications. The assignment covers tasks such as creating a HashMap, retrieving values, checking for keys and values, updating entries, and handling character and word frequency counts. Additionally, it includes bonus interview questions that address advanced HashMap topics and performance considerations.

Uploaded by

vineet Tiwari
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)
2 views2 pages

Java HashMap Practice Assignment

This document is a Java HashMap practice assignment that includes a series of questions designed to enhance students' understanding of HashMap concepts, ranging from basic operations to more complex applications. The assignment covers tasks such as creating a HashMap, retrieving values, checking for keys and values, updating entries, and handling character and word frequency counts. Additionally, it includes bonus interview questions that address advanced HashMap topics and performance considerations.

Uploaded by

vineet Tiwari
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

Java HashMap Practice Assignment

Easy to Tricky Questions

This assignment is designed to help students master Java HashMap concepts from beginner to
interview level. Attempt all questions before looking at solutions.

Q1. Create a HashMap of Integer and String. Add 5 student IDs and names, then print the map.

Q2. Retrieve the value associated with a given key from a HashMap.

Q3. Check whether a particular key exists in the HashMap.

Q4. Check whether a particular value exists in the HashMap.

Q5. Update the value of an existing key and print the updated map.

Q6. Remove a key-value pair from the HashMap and display the remaining entries.

Q7. Iterate through all entries using entrySet() and print key and value separately.

Q8. Find the size of a HashMap and print all keys and all values separately.

Q9. Count the frequency of each character in a given string using HashMap.

Q10. Count the frequency of each word in a sentence using HashMap.

Q11. Given an array of integers, find the first non-repeating element using HashMap.

Q12. Given an array of integers, find all duplicate elements using HashMap.

Q13. Create an Employee class (id, name, salary) and store Employee objects in a HashMap. Print
employees with salary greater than 50,000.

Q14. Given two strings, determine whether they are anagrams using HashMap.

Q15. Design a mini student result system using HashMap where roll number is the key and marks
are the value. Find the topper, average marks, and failed students.
Bonus Interview Questions
• What is the difference between HashMap, LinkedHashMap, and TreeMap?

• Why is the average time complexity of get() and put() O(1)?

• How does HashMap handle collisions internally?

• What happens if two keys have the same hashCode()?

• Why must equals() and hashCode() be overridden together?

You might also like