Here you can find the source of reverseMap(Map
public static <K, V> Map<V, K> reverseMap(Map<K, V> map)
//package com.java2s; //License from project: Apache License import java.util.HashMap; import java.util.Map; public class Main { public static <K, V> Map<V, K> reverseMap(Map<K, V> map) { Map<V, K> ret = new HashMap<V, K>(); for (K key : map.keySet()) { ret.put(map.get(key), key);// w ww. j a va2s . co m } return ret; } public static <S, T> T get(Map<S, T> m, S key, T def) { T ret = m.get(key); if (ret == null) { ret = def; } return ret; } }