Drag the edges to resize the window.

Code Editor
Data Structures

HashMap: Manipulation

Perfect! Now let's fill the HashMap with useful data.

Add keys and values to a HashMap:

HashMap<String, Integer> myFriends = new HashMap<String, Integer>(); myFriends.put("Mark", 24); myFriends.put("Cassandra", 25); myFriends.put("Zenas", 21);

In the example above, we used the put method to add a String key and an associated Integer value. The String key is the text inside double quotes " ". The Integer value is represented by the number.

Report a Bug
If you see a bug or any other issue with this page, please report it here.