java hashmap entryset
for (Map.Entry<String, String> entry : yourHashMap.entrySet()) {
System.out.println(entry.getKey() + " = " + entry.getValue());
}
java hashmap entryset
for (Map.Entry<String, String> entry : yourHashMap.entrySet()) {
System.out.println(entry.getKey() + " = " + entry.getValue());
}
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;
}
}
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us