Here you can find the source of invertMap(Map
Parameter | Description |
---|---|
V | the value type |
K | the key type |
map | the map |
private static <V, K> Map<V, K> invertMap(Map<K, V> map)
//package com.java2s; //License from project: Apache License import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; public class Main { /**/*from ww w . java 2 s .co m*/ * Invert map. * * @param <V> * the value type * @param <K> * the key type * @param map * the map * @return the map */ private static <V, K> Map<V, K> invertMap(Map<K, V> map) { Map<V, K> inv = new HashMap<V, K>(); for (Entry<K, V> entry : map.entrySet()) inv.put(entry.getValue(), entry.getKey()); return inv; } }