Java Map Invert invertMap(Map map)

Here you can find the source of invertMap(Map map)

Description

Invert map.

License

Apache License

Parameter

Parameter Description
V the value type
K the key type
map the map

Return

the map

Declaration

private static <V, K> Map<V, K> invertMap(Map<K, V> map) 

Method Source Code

//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;
    }
}

Related

  1. invertMap(final Map map)
  2. invertMap(final Map map)
  3. invertMap(Map map)
  4. invertMap(Map map)
  5. invertMap(Map map)
  6. invertMap(Map map)
  7. invertStringMap(Map input)