Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java map key set

import java.util.HashMap;
import java.util.Map;
 
class Main
{
    public static <K, V> K getKey(Map<K, V> map, V value)
    {
        for (K key: map.keySet())
        {
            if (value.equals(map.get(key))) {
                return key;
            }
        }
        return null;
    }
 
    public static void main(String[] args)
    {
        Map<String, Integer> hashMap = new HashMap();
        hashMap.put("A", 1);
        hashMap.put("B", 2);
        hashMap.put("C", 3);
 
        System.out.println(getKey(hashMap, 2));        // prints `B`
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: determine if a number is factorial in Java 
Java :: get field name java 
Java :: android studio int ot string 
Java :: LRU Cache java 
Java :: how to get filename without extension in java 
Java :: java store data 
Java :: index 1 out of bound for length 1 java 
Java :: string vs new string 
Java :: how to skip a line with a filewriter java 
Java :: hashtable in java 
Java :: encode file to utf-8 in java 
Java :: limit decimals java 
Java :: how to remove last latter in word in java 
Java :: lambda expression java 
Java :: add random numbers to array 
Java :: java float data type 
Java :: navigation bottom android 
Java :: java servlet life cycle 
Java :: CORS with Spring Boot 
Java :: run jar file with different jre 
Java :: java application 
Java :: check if object is empty java 8 
Java :: javafx 
Java :: writeToFileAsync java 
Java :: colors java intell print 
Java :: Java Custom Annotations 
Java :: get sha1 key from keystore 
Java :: Transversal operation in java array 
Java :: java load configuration log 
Java :: java 8 lambda delete from list 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =