Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

JAVA HashMap get keys by values

    Map<String, String> map = new HashMap<String, String>();
    
    map.put("abc", "123");
    map.put("xyz", "456");
    
    for(Entry<String, String> entry : map.entrySet()) {
        if(entry.getValue().equalsIgnoreCase("456")) {
            System.out.println(entry.getKey());
        }
    }
Comment

get key from value hashmap

import java.util.HashMap;
import java.util.Map.Entry;

class Main {
  public static void main(String[] args) {

    // create a hashmap
    HashMap<String, Integer> numbers = new HashMap<>();
    numbers.put("One", 1);
    numbers.put("Two", 2);
    numbers.put("Three", 3);
    System.out.println("HashMap: " + numbers);

    // value whose key is to be searched
    Integer value = 3;

    // iterate each entry of hashmap
    for(Entry<String, Integer> entry: numbers.entrySet()) {

      // if give value is equal to value from entry
      // print the corresponding key
      if(entry.getValue() == value) {
        System.out.println("The key for value " + value + " is " + entry.getKey());
        break;
      }
    }
  }
}
Comment

hashmap get value java


//Import Hashmap
import java.util.HashMap;
   
    HashMap<String, String> dir = new HashMap<String, String>();
//Add key, values  
    dir.put("hi", "hello");
	dir.put("wow", "amazing");
//print value for hi.
    System.out.println(dir.get("hi");
Comment

PREVIOUS NEXT
Code Example
Java :: import android.support.v7.app.alertdialog androidx 
Java :: hibernate in spring boot 
Java :: setting java home 
Java :: first line of java code 
Java :: fibonacci series in java 
Java :: hashmap in java 
Java :: java character 
Java :: thread java timer 
Java :: java create xml 
Java :: java get class name of object 
Java :: adjust font scale in android studio 
Java :: java methods 
Java :: convert date to localdate java 
Java :: add two variables in Java 
Java :: Java Type conversion from String to int 
Java :: binary to decimal java 
Java :: java hash map 
Java :: how to convert 2d to 1d array in java 
Java :: reverse loop in java 
Java :: Java List Add Elements using add() method 
Java :: android foreground services set auto cancel not working 
Java :: android studio clock bar change color programmatically 
Java :: how to compute age from local date 
Java :: How to get the nth Fibonacci number code in Java using recursion with memoization 
Java :: how to delete an element from an array in java data structure 
Java :: java convert double to boolean 
Java :: java check if int is null 
Java :: how to run few methods of class after mockStatic 
Java :: java words from file 
Java :: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:251) 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =