Java HashMap Reverse reverseHashMap(HashMap map)

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

Description

reverse Hash Map

License

Open Source License

Declaration

public static <A, B> HashMap<B, A> reverseHashMap(HashMap<A, B> map) 

Method Source Code

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

import java.util.HashMap;

public class Main {
    public static <A, B> HashMap<B, A> reverseHashMap(HashMap<A, B> map) {
        HashMap<B, A> reverseMap = new HashMap<B, A>();
        for (A a : map.keySet()) {
            B b = map.get(a);//from  w  w  w.j  av  a  2  s . c  o  m
            reverseMap.put(b, a);
        }
        return reverseMap;
    }
}

Related

  1. reverseHashMap(Map map)