get(Object): This method is available in java.util.WeakHashMap class of Java.
Syntax:
V java.util.WeakHashMap.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.WeakHashMap;public class WeakHashMapget {public static void main(String[] args) {WeakHashMap<String, String> weakHashMap =new WeakHashMap<String, String>();weakHashMap.put("Java", "Program");weakHashMap.put("Hello", "World");Object key = "Java";System.out.println(weakHashMap.get(key));}}
Output:
Program
No comments:
Post a Comment