Java Map Invert invertStringMap(Map input)

Here you can find the source of invertStringMap(Map input)

Description

Inverts Map of Strings (values become keys, keys become values).

License

Open Source License

Parameter

Parameter Description
input Map to invert

Return

inverted Map

Declaration

public static HashMap<String, String> invertStringMap(Map<String, String> input) 

Method Source Code

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

import java.util.HashMap;

import java.util.Map;

import java.util.Set;

public class Main {
    /**/* w w w  .j av a2 s  .com*/
     * Inverts Map of Strings (values become keys, keys become values).
     * @param input Map to invert
     * @return inverted Map
     */
    public static HashMap<String, String> invertStringMap(Map<String, String> input) {

        HashMap<String, String> output = new HashMap<String, String>(input.size());

        Set<Map.Entry<String, String>> entries = input.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            output.put(entry.getValue(), entry.getKey());
        }

        return output;

    }
}

Related

  1. invertMap(Map map)
  2. invertMap(Map map)
  3. invertMap(Map map)
  4. invertMap(Map map)
  5. invertMap(Map map)