Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java iterate through map

for (Map.Entry<String, Object> entry : map.entrySet()) {
    String key = entry.getKey();
    Object value = entry.getValue();
    // ...
}
Comment

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);
		}
	}
}
Comment

Iterating through a map

for (auto const& [key, value] : your_map) {
  std::cout << key    << ':'    << value    << std::endl;
}
Comment

PREVIOUS NEXT
Code Example
Java :: calling java static method in kotlin 
Java :: javafx list view does not update 
Java :: Print Text Using Java 
Java :: enhance for loop java 
Java :: java list remove 
Java :: java array merge 
Java :: flutter webview plugin background transparent 
Java :: array.swap java 
Java :: list of strings java 
Java :: how to get the memory location of an object in java 
Java :: java inner function 
Java :: enable cors on apache tomcat 
Java :: redshift establish connection jav gradle 
Java :: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 
Java :: java string equals null 
Java :: array copy java 
Java :: java resultset to table 
Java :: java programme for fibonnaci series 
Java :: java create array with values 
Java :: java stream add to existing list 
Java :: android studio check if email is valid java 
Java :: qr code spring boot 
Java :: java indexof nth occurrence 
Java :: java complex numbers 
Java :: Java Remove HashMap Elements 
Java :: Java Create a ByteArrayOutputStream 
Java :: interface vs abstract class java 
Java :: How to Initialize Arrays in Java? 
Java :: how do you handle exceptions in java 
Java :: configure JWT on Springboot 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =