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

Traversing through java map foreach

// Java Program to Demonstrate
// Working of Map interface

// Importing required classes
import java.util.*;

// Main class
class Main {

	// Main driver method
	public static void main(String args[])
	{
		// Creating an empty HashMap
		Map<String, Integer> hashmap= new HashMap<String, Integer>();

		// Inserting pairs in above Map
		// using put() method
		hashmap.put("Banana", new Integer(100));
		hashmap.put("Orange", new Integer(200));
		hashmap.put("Mango", new Integer(300));
		hashmap.put("Apple", new Integer(400));

		// Traversing through Map using for-each loop
		for (Map.Entry<String, Integer> map :
			hashmap.entrySet()) {

			// Printing keys
			System.out.print(map.getKey() + ":");
			System.out.println(map.getValue());
		}
	}
}
Comment

PREVIOUS NEXT
Code Example
Java :: get current location android 
Java :: java questions 
Java :: Java telegram bot dependency 
Java :: long java 
Java :: java store data 
Java :: fragment call activity 
Java :: java int 0/0 
Java :: set style programmatically android 
Java :: Java Remove ArrayList Elements 
Java :: Set icon for toolbar android 
Java :: parameterized constructor java 
Java :: look and feel java 
Java :: capture console output java 
Java :: Java Method Create Basic 
Java :: string length java 
Java :: Implementing the LinkedList Class in java list 
Java :: android studio convert java to kotlin 
Java :: java append to array 
Java :: springboot validator manually validate 
Java :: can we serialize class in java 
Java :: sum of array in java 
Java :: camunda 
Java :: java eth 
Java :: java truncate bigdecimal 
Java :: preset arraylist java 
Java :: and two editText fields in android studio 
Java :: access db in fragments 
Java :: java namespaces 
Java :: Exercise. Create a simple Java program using array named SumOfArray.java that will accept an input of whole numbers or floating point numbers and will return the Sum result. The program must accept at least 5 numbers. 
Java :: change button background drawable in code Close 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =