0% found this document useful (0 votes)
139 views1 page

Java HashMap Functions Cheat Sheet

This document is a cheat sheet for Java HashMap functions, detailing key methods and their descriptions. It includes examples for each function such as put, get, remove, and size. The cheat sheet serves as a quick reference for developers working with HashMaps in Java.

Uploaded by

rajnishr0001
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)
139 views1 page

Java HashMap Functions Cheat Sheet

This document is a cheat sheet for Java HashMap functions, detailing key methods and their descriptions. It includes examples for each function such as put, get, remove, and size. The cheat sheet serves as a quick reference for developers working with HashMaps in Java.

Uploaded by

rajnishr0001
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 Cheat Sheet

Function Description Example

put(key, value) Insert or update a key-value pair [Link]("Apple", 10);


get(key) Return value for given key (null if absent) [Link]("Apple");
getOrDefault(key, def) Return value if key exists, else default [Link]("Mango", 0);
containsKey(key) Check if a key exists [Link]("Banana");
containsValue(value) Check if a value exists [Link](5);
remove(key) Remove mapping for key [Link]("Banana");
size() Return number of key-value pairs [Link]();
isEmpty() Check if map is empty [Link]();
clear() Remove all entries [Link]();
keySet() Return set of all keys [Link]();
values() Return collection of all values [Link]();
entrySet() Return set of all key-value pairs [Link]();
replace(key, val) Update value for a key if exists [Link]("Apple", 50);
putIfAbsent(key, val) Add entry if key not already present [Link]("Grapes", 20);

You might also like