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

java hashmap get array of keys

for (int key : myHashMap.keySet()){
	// do stuff
}
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

PREVIOUS NEXT
Code Example
Java :: how to get int from string java 
Java :: multiplication of two numbers in java using scanner 
Java :: bytes to string solidity 
Java :: Problem adding rectangle in javaFX 
Java :: how to do infinte loop in java 
Java :: how to get key value from json object in java 
Java :: java summe array 
Java :: error cannot find symbol intent 
Java :: contains hashmap java 
Java :: remove all new line and other in string using java 
Java :: odd number in java 
Java :: open camera or gallery on button click android 
Java :: java stream distinct by key 
Java :: containskey in java 
Java :: can strings be used in a 2 dimensional array in java 
Java :: print list array 
Java :: set size button java 
Java :: cannot find symbol variable log 
Java :: int array java 
Java :: how to get data from radio group in android 
Java :: spring boot actuator 
Java :: compare two character alphabetically java 
Java :: how to find numbers of digits in java 
Java :: timestamp with zone java 
Java :: open website from android activity 
Java :: java get relative path 
Java :: java hash password 
Java :: java declare a list 
Java :: android studio download 
Java :: int [] to Integer[] 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =