Java Map Reverse reverseMap(Map map)

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

Description

'reverse' a map's key and values, beware this may cause losing some entries(values may have duplications)

License

Open Source License

Parameter

Parameter Description
gruleTypeMapping a parameter

Declaration

public static <K, V> Map<V, K> reverseMap(Map<K, V> map) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2012 pf_miles.//from  w  w  w  .jav a2 s  .  c  o  m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     pf_miles - initial API and implementation
 ******************************************************************************/

import java.util.HashMap;

import java.util.Map;

public class Main {
    /**
     * 'reverse' a map's key and values, beware this may cause losing some
     * entries(values may have duplications)
     * 
     * @param gruleTypeMapping
     * @return
     */
    public static <K, V> Map<V, K> reverseMap(Map<K, V> map) {
        Map<V, K> ret = new HashMap<V, K>();
        for (Map.Entry<K, V> e : map.entrySet()) {
            ret.put(e.getValue(), e.getKey());
        }
        return ret;
    }
}

Related

  1. reverseMap(List listSeq)
  2. reverseMap(Map map)
  3. reverseMap(Map map)
  4. reverseMap(Map map)
  5. reverseMap(Map map)
  6. reverseMap(Map origMap)
  7. reverseMap(Map map)
  8. reverseMap(Map keyIdMap, Map keyValueMap)
  9. reverseMapLookup(Map map, V value)