java iterate through map
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
// ...
}
java iterate through map
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
// ...
}
Iterating Through the Java Map
// Java program to demonstrate
// the working of Map interface
import java.util.*;
class Main {
public static void main(String args[])
{
// Initialization of a Map
// using Generics
Map<Integer, String> hashmap1= new HashMap<Integer, String>();
// Inserting the Elements
hashmap1.put(1, "Apple");
hashmap1.put(2, "Banana");
hashmap1.put(3, "Mango");
for (Map.Entry mapElement : hashmap1.entrySet()) {
int key= (int)mapElement.getKey();
// Finding the value
String value= (String)mapElement.getValue();
System.out.println(key + " : "+ value);
}
}
}
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