Java HashMap Exercises, Practice & Solutions
Java Collection: HashMap Exercises [12 exercises with solution]
[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]
HashMap:
In Java, HashMap is an implementation of the Map interface provided by the Java Collections Framework. It's part of the java.util package.
1. Write a Java program to associate the specified value with the specified key in a HashMap.
Click me to see the solution
2. Write a Java program to count the number of key-value (size) mappings in a map.
Click me to see the solution
3. Write a Java program to copy all mappings from the specified map to another map.
Click me to see the solution
4. Write a Java program to remove all mappings from a map.
Click me to see the solution
5. Write a Java program to check whether a map contains key-value mappings (empty) or not.
Click me to see the solution
6. Write a Java program to get a shallow copy of a HashMap instance.
Click me to see the solution
7. Write a Java program to test if a map contains a mapping for the specified key.
Click me to see the solution
8. Write a Java program to test if a map contains a mapping for the specified value.
Click me to see the solution
9. Write a Java program to create a set view of the mappings contained in a map.
Click me to see the solution
10. Write a Java program to get the value of a specified key in a map.
Click me to see the solution
11. Write a Java program to get a set view of the keys contained in this map.
Click me to see the solution
12. Write a Java program to get a collection view of the values contained in this map.
Click me to see the solution
Java Practice online
More to Come !
Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics