get(Object): This method is available in java.util.HashMap class of Java.
Syntax:
V java.util.HashMap.get(Object key)
This method takes one argument. This method returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
Parameters: One parameter is required for this method.
key: the key whose associated value is to be returned.
Returns: the value to which the specified key is mapped, or null if this map contains no mapping for the key.
Exceptions: NA
Approach
Java
import java.util.HashMap;public class HashMapget {public static void main(String[] args) {HashMap<String, Integer> hashMap =new HashMap<String, Integer>();hashMap.put("Hello", 1);hashMap.put("World", 2);Object key = "Hello";System.out.println(hashMap.get(key));}}
Output:
1
No comments:
Post a Comment