Its a starter question, I want to swap keys with values and vice versa of a HashMap
. Here's what I've tried so far.
import java.util.HashMap;
import java.util.Map;
class Swap{
public static void main(String args[]){
HashMap<Integer, String> s = new HashMap<Integer, String>();
s.put(4, "Value1");
s.put(5, "Value2");
for(Map.Entry en:s.entrySet()){
System.out.println(en.getKey() + " " + en.getValue());
}
}
}