Java tutorial
//package com.java2s; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; public class Main { @SuppressWarnings("rawtypes") public static Map<String, Integer> swapIntKeysAndStrValues(Map<Integer, String> hm) { HashMap<String, Integer> nhm = new HashMap<String, Integer>(); Set<?> s = hm.entrySet(); Iterator<?> it = s.iterator(); while (it.hasNext()) { Map.Entry m = (Map.Entry) it.next(); nhm.put((String) m.getValue(), (Integer) m.getKey()); } return nhm; } }