get Key Of Map By Value - Java java.util

Java examples for java.util:Map Key

Description

get Key Of Map By Value

Demo Code


//package com.book2s;
import java.util.HashMap;
import java.util.Iterator;

public class Main {
    /**//from   www  . j av a2 s. c o  m
     *
     * @param map
     * @param aInteger
     * @return
     */
    public static String getKeyOfMapByValue(HashMap<String, Integer> map,
            Integer aInteger) {
        Iterator<String> it = map.keySet().iterator();
        while (it.hasNext()) {
            String keyString = it.next();
            if (map.get(keyString).equals(aInteger))
                return keyString;
        }
        return null;
    }
}

Related Tutorials