I have 2 questions regarding the code bellow,
1.I have the key "two" twice in my hashmap, while printing, "two" is displayed only once.Why its not displaying "two" twice?
2.How to selectively display the key "two"?
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
public class main {
public static void main(String[] args){
HashMap<String,String> myMap = new HashMap<String,String>();
myMap.put("one", "1");
myMap.put("two", "2");
myMap.put("three", "3");
myMap.put("two", "4");
Set <String> mySet =myMap.keySet();
Iterator itr = mySet.iterator();
while(itr.hasNext()){
String key = (String) itr.next();
System.out.println(key);
}
}
}