Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Map;
import java.util.Set;

public class Main {

    public static <K, V> K getKeyByValue(Map<K, V> map, V value) {
        Set<Map.Entry<K, V>> entrySet = map.entrySet();
        for (Map.Entry<K, V> entry : entrySet) {
            if ((entry.getValue() == value) || ((entry.getValue() != null) && (entry.getValue().equals(value)))) {
                return entry.getKey();
            }
        }
        return null;
    }
}