Here you can find the source of invertMap(Map
public static <V, K> Map<V, K> invertMap(Map<K, V> map)
//package com.java2s; //License from project: Open Source License import java.util.HashMap; import java.util.Map; public class Main { public static <V, K> Map<V, K> invertMap(Map<K, V> map) { Map<V, K> inverted = new HashMap<V, K>(); for (Map.Entry<K, V> entry : map.entrySet()) { inverted.put(entry.getValue(), entry.getKey()); }//from w ww. j av a2 s .co m return inverted; } }