Here you can find the source of invertStringMap(Map
Parameter | Description |
---|---|
input | Map to invert |
public static HashMap<String, String> invertStringMap(Map<String, String> input)
//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; } }