public static void main(String[] args) { Map<String, String> map = new HashMap<String, String>(); map.put("key1", "value1"); map.put("key2", "value2"); map.put("key3", "value3"); Set<String> keySet = map.keySet(); int i = map.size()-1; Map<Integer, String> mapKey = new HashMap<Integer, String>(); Map<Integer, String> mapValue = new HashMap<Integer, String>(); for(java.util.Map.Entry<String, String> entry : map.entrySet()) { //将原来MAP的VALUE放入新的MAP的VALUE里面 mapKey.put(i, entry.getValue()); //将原来MAP的KEY放入新的MAP的VALUE 里面 mapValue.put(i, entry.getKey()); i--; } //打印KEY值 System.out.println(mapKey.get(2)); //打印VALUE值 System.out.println(mapValue.get(0)); }
转载于:https://blog.51cto.com/8985556/1665662