AbstractMap.get()
is a method of the Java AbstractMap class. We use it to return the value a specified key maps to in the AbstractMap maps, or to return NULL
if the AbstractMap contains no mapping for the specified key.
AbstractMap.get(Object key);
The AbstractMap.get()
method takes one parameter, Object
We can write the illustration shown above in the code snippet below.
import java.util.*;class AbstractMapDemo {public static void main(String[] args){// Creating an AbstractMapAbstractMap<Integer, String>abstractMap = new HashMap<Integer, String>();// Mapping string values to int keysabstractMap.put(21, "Shot");abstractMap.put(42, "Java");abstractMap.put(34, "Yaaaayy");// Printing the AbstractMapSystem.out.println("The Mappings are: "+ abstractMap);// Getting the value of key 21System.out.println("The value of key 21 is: "+ abstractMap.get(21));// Getting the value of key 35System.out.println("The value of key 34 is: "+ abstractMap.get(35));}}