java hashmap get from value code example
Example 1: hashmap get value java
import java.util.HashMap;
HashMap<String, String> dir = new HashMap<String, String>();
dir.put("hi", "hello");
dir.put("wow", "amazing");
System.out.println(dir.get("hi");
Example 2: java hashmap get value
package com.tutorialspoint;
import java.util.*;
public class HashMapDemo {
public static void main(String args[]) {
HashMap newmap = new HashMap();
newmap.put(1, "tutorials");
newmap.put(2, "point");
newmap.put(3, "is best");
String val = (String)newmap.get(3);
System.out.println("Value for key 3 is: " + val);
}
}