Here you can find the source of reverseHashMap(Map extends T, ? extends U> map)
public static <T, U> Map<U, T> reverseHashMap(Map<? extends T, ? extends U> map)
//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; } }