Java Map Invert invertMap(final Map map)

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

Description

invert Map

License

Open Source License

Declaration

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

Method Source Code

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

Related

  1. invert(Map in)
  2. invert(Map map)
  3. invert(Map map, String prefix)
  4. invert(Map map)
  5. invertedMapFrom(Map source)
  6. invertMap(final Map map)
  7. invertMap(Map map)
  8. invertMap(Map map)
  9. invertMap(Map map)