Map get() method in Java with Examples Last Updated : 07 May, 2023 Comments Improve Suggest changes Like Article Like Report The get() method of Map interface in Java is used to retrieve or fetch the value mapped by a particular key mentioned in the parameter. It returns NULL when the map contains no such mapping for the key. So, let us check how to get value from the map in Java. Syntax of get() method in JavathisMap.get(Object key_element)Parameter and Return Value of get() method Parameter: The method takes one parameter key_element of object type and refers to the key whose associated value is supposed to be fetched. Return Value: The method returns the value associated with the key_element in this Map collection. Return Type of get() method The Return Type of the get() method depends on the data type or what datatypes we have passed in the parameter. Below we have mentioned two cases explaining how to use get() method and to get which return type. Case 1: In this case, the return type of get() method will be Integer because the data type initialized in map key value is Integer. Map<String,Integer> map=new HashMap<>(); Below is the Implementation of the above Case: Java // Java Program to demonstrate // Mapping Integer Values to String Keys. import java.util.*; public class Map_Demo { public static void main(String[] args) { // Creating an empty Map Map<String, Integer> map = new HashMap<String, Integer>(); // Mapping int values to string keys map.put("Geeks", 10); map.put("4", 15); map.put("Geeks", 20); map.put("Welcomes", 25); map.put("You"", 30); // Displaying the Map System.out.println("Initial Mappings are: " + map); // Getting the value of "Geeks" System.out.println("The Value is: " + map.get("Geeks")); // Getting the value of "You" System.out.println("The Value is: " + map.get("You")); } } Output:Initial Mappings are: {4=15, Geeks=20, You=30, Welcomes=25} The Value is: 20 The Value is: 30 Case 2: Here it will return String. Map<Integer,String> map=new HashMap<>(); The below programs illustrate the working of java.util.Map.get() method. Java // Java Program to demonstrate the // Mapping String Values to Integer Keys import java.util.*; public class Map_Demo { public static void main(String[] args) { // Creating an empty Map Map<Integer, String> map = new HashMap<Integer, String>(); // Mapping string values to int keys map.put(10, "Geeks"); map.put(15, "4"); map.put(20, "Geeks"); map.put(25, "Welcomes"); map.put(30, "You"); // Displaying the Map System.out.println("Initial Mappings are: " + map); // Getting the value of 25 System.out.println("The Value is: " + map.get(25)); // Getting the value of 10 System.out.println("The Value is: " + map.get(10)); } } Output:Initial Mappings are: {20=Geeks, 25=Welcomes, 10=Geeks, 30=You, 15=4} The Value is: Welcomes The Value is: Geeks Note: The same operation can be performed with any type of Mappings with variation and combination of different data types. The return type will depend on the data type passed in the HashMap. Reference: Official documentation Comment More infoAdvertise with us Next Article Java Map hashCode() Method gopaldave Follow Improve Article Tags : Java Java-Collections Java-Functions java-map Practice Tags : JavaJava-Collections Similar Reads Map Interface in Java In Java, the Map Interface is part of the java.util package and represents a mapping between a key and a value. The Java Map interface is not a subtype of the Collections interface. So, it behaves differently from the rest of the collection types.Key Features:No Duplicates in Keys: Keys should be un 11 min read Map put() Method in Java with Examples The Map put() method associates the specified value with the specified key in the map. The map put() method is used to insert new key-value pairs inside a map in Java. If the map already contains the mapping for the specified key, the old value is replaced by the new specified value. Example: Java / 3 min read Map remove() Method in Java with Examples The map.remove() method is used to remove the mapping for a key from this map if it is present in the map. Syntax: V remove(Object key)Parameters: This method has the only argument key, whose mapping is to be removed from the map.Returns: This method returns the value to which this map previously as 2 min read Map clear() method in Java with Example The java.util.Map.clear() method in Java is used to clear and remove all of the elements or mappings from a specified Map collection. Syntax: void clear() Parameters: The method does not accept any parameters. Return Value: The method does not return any value. Below programs are used to illustrate 2 min read Map containsKey() method in Java with Examples The java.util.Map.containsKey() method is used to check whether a particular key is being mapped into the Map or not. It takes the key element as a parameter and returns True if that element is mapped in the map. Syntax: boolean containsKey(key_element) Parameters: The method takes just one paramete 2 min read Map containsValue() method in Java with Examples The java.util.Map.containsValue() method is used to check whether a particular value is being mapped by a single or more than one key in the Map. It takes the value as a parameter and returns True if that value is mapped by any of the key in the map. Syntax: boolean containsValue(Object Value) Param 2 min read Map entrySet() method in Java with Examples The java.util.Map.entrySet() method in Java is used to create a set out of the same elements contained in the map. It basically returns a set view of the map or we can create a new set and store the map elements into them. Syntax: map.entrySet() Parameters: The method does not take any parameter. Re 2 min read Java Map equals() Method The equals() method of Map interface in Java is used to check if two maps are equal. Two maps are considered equal if they meet the following conditions. Both maps must have the same size.Both maps must contain identical key-value pairs. (It means every key in one map must be associated with the sam 2 min read Map get() method in Java with Examples The get() method of Map interface in Java is used to retrieve or fetch the value mapped by a particular key mentioned in the parameter. It returns NULL when the map contains no such mapping for the key. So, let us check how to get value from the map in Java. Syntax of get() method in JavathisMap.get 3 min read Java Map hashCode() Method In Java, the hashCode() method is a part of the Object class and is used to generate a hash code value for an object. Example 1: Hash Code for Different ObjectsThe below Java program demonstrates that every object has a unique hashcode. Java// Java program to demonstrates hashCode() // for different 2 min read Like