Here you can find the source of invertedMapFrom(Map
Parameter | Description |
---|---|
source | Map |
public static <K, V> Map<V, K> invertedMapFrom(Map<K, V> source)
//package com.java2s; /**//from w ww . j a v a 2 s . c o m * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ import java.util.HashMap; import java.util.Map; public class Main { /** * Returns a map based on the source but with the key & values swapped. * * @param source * Map * @return Map */ public static <K, V> Map<V, K> invertedMapFrom(Map<K, V> source) { Map<V, K> map = new HashMap<>(source.size()); for (Map.Entry<K, V> entry : source.entrySet()) { map.put(entry.getValue(), entry.getKey()); } return map; } }