java实现:根据 map的value值获取key值

    /**
     * 根据 map的value值获取key值
     * @param map
     * @param value
     * @return
     */
    public static String getKeyFromValue(Map<String, String> map, String value) {
        String mKey = "";
        Set<String> keySet = map.keySet();
        for (String key : keySet) {
            if ( value.equals(map.get(key)) ) {
                mKey = key;
            }
        }
        return mKey;
    }

 

posted @ 2023-06-05 15:37  petercao  阅读(680)  评论(0编辑  收藏  举报