Java HashMap Reverse reverseHashMap(Map map)

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

Description

reverse Hash Map

License

Open Source License

Declaration

public static <T, U> Map<U, T> reverseHashMap(Map<? extends T, ? extends U> map) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.HashMap;

import java.util.Map;
import java.util.Map.Entry;

public class Main {
    public static <T, U> Map<U, T> reverseHashMap(Map<? extends T, ? extends U> map) {
        Map<U, T> ret = new HashMap<>(map.size());
        for (Entry<? extends T, ? extends U> entr : map.entrySet()) {
            ret.put(entr.getValue(), entr.getKey());
        }/*from   w ww  .  j  a  v a  2s  .c  om*/
        return ret;
    }
}

Related

  1. reverseHashMap(HashMap map)