Here you can find the source of invertMap(final Map
private static <K, V> Map<V, K> invertMap(final Map<K, V> map)
//package com.java2s; /*// w w w . j ava 2 s .c om * Copyright (c) 2015 Gargoyle Software Inc. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (http://www.gnu.org/licenses/). */ import java.util.Collections; import java.util.IdentityHashMap; import java.util.Map; public class Main { private static <K, V> Map<V, K> invertMap(final Map<K, V> map) { final Map<V, K> inverted = new IdentityHashMap<>(map.size()); for (final Map.Entry<K, V> entry : map.entrySet()) { inverted.put(entry.getValue(), entry.getKey()); } return Collections.unmodifiableMap(inverted); } }