Adding Elements In to map
Map is an interface you need to instantiate a concrete implementation of the interface in order to retrive element.
import java.util.HashMap;
import java.util.Map;
public class HashMapExample {
}
public static void main(String[] args) {
//create an instance of HashMap to Store Phone Number
Map exampleUserMap = new HashMap();
//Populate example map with values
exampleUserMap.put("mona", 4512147);
exampleUserMap.put("sona", 54769);
exampleUserMap.put("imran", 47147);
exampleUserMap.put("irfan", 74444Aryantech Pune
8);
for (Map.Entry entry : exampleUserMap.entrySet()) {
System.out.println("Key = " + entry.getKey() + ", Value = " +
entry.getValue());
}
}
}
Aryantech pune
No comments:
Post a Comment