Saturday 29 June 2013

Searching an element in HashMap in java

1. Creating a java class with main method and implementing map collection

package map.search.value;

import java.util.HashMap;
import java.util.Map;

public class TestHashMapSearch {
public static void main(String[] args) {
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("Amir", 65676665);
map.put("Samma", 97653244);
map.put("Qunal", 011563435);
map.put("Nibbil", 88088099);
map.put("Suprema", 342267788);
map.put("Janiya", 990099434);
//If there is multiple kay as Amir then it will pick up last value
System.out.println("Value with correspondent key is: "+map.get("Amir"));
}

}

2. Out put


Value with correspondence key is: 65676665

No comments:

Post a Comment