iterate over map keys java
Java
public static void printMap(Map mp) {
Iterator it = mp.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
System.out.println(pair.getKey() + " = " + pair.getValue());
it.remove(); // avoids a ConcurrentModificationException
}
}// Java program for traversing
// through a hashmap using for-each loop
import java.util.*;
class GfG {
public static void main(String[] args)
{
// Consider the hashmap containing
// student name and their marks
HashMap<String, Integer> hm =
new HashMap<String, Integer>();
// Adding mappings to HashMap
hm.put("GeeksforGeeks", 54);
hm.put("A computer portal", 80);
hm.put("For geeks", 82);
// Printing the HashMap
System.out.println("Created hashmap is" + hm);
// Loop through the hashmap
System.out.println("HashMap after adding bonus marks:");
// Using for-each loop
for (Map.Entry mapElement : hm.entrySet()) {
String key = (String)mapElement.getKey();
// Add some bonus marks
// to all the students and print it
int value = ((int)mapElement.getValue() + 10);
System.out.println(key + " : " + value);
}
}
}
// Java program to demonstrate iteration over
// Map.entrySet() entries using for-each loop
import java.util.Map;
import java.util.HashMap;
class IterationDemo
{
public static void main(String[] arg)
{
Map<String,String> gfg = new HashMap<String,String>();
// enter name/url pair
gfg.put("GFG", "geeksforgeeks.org");
gfg.put("Practice", "practice.geeksforgeeks.org");
gfg.put("Code", "code.geeksforgeeks.org");
gfg.put("Quiz", "quiz.geeksforgeeks.org");
// using for-each loop for iteration over Map.entrySet()
for (Map.Entry<String,String> entry : gfg.entrySet())
System.out.println("Key = " + entry.getKey() +
", Value = " + entry.getValue());
}
}
Also in Java:
- Title
- firebase connecten
- Category
- Java
- Title
- read integer input java
- Category
- Java
- Title
- spigot title
- Category
- Java
- Title
- regex get string between quotes java
- Category
- Java
- Title
- how to check the end of a string java
- Category
- Java
- Title
- get sha key android
- Category
- Java
- Title
- java program to get all cat indices in elasticsearch javadoc
- Category
- Java
- Title
- android get distance between two locations kotlin
- Category
- Java
- Title
- java 8 add whole array to jsonarray
- Category
- Java
- Title
- how to skip a line in java
- Category
- Java
- Title
- inline foreach java
- Category
- Java
- Title
- java taking console input
- Category
- Java
- Title
- simple calculator program in java
- Category
- Java
- Title
- java append to array
- Category
- Java
- Title
- how to compare two maps in java
- Category
- Java
- Title
- reverse number in java
- Category
- Java
- Title
- how to use spring in java
- Category
- Java
- Title
- restart application programmatically android
- Category
- Java
- Title
- create java windows application
- Category
- Java
- Title
- java replace all html tags
- Category
- Java
- Title
- how to check if a string contains only alphabets and space in java
- Category
- Java
- Title
- java list contains object with property
- Category
- Java
- Title
- java 8 hashmap example stackoverflow
- Category
- Java
- Title
- java run project from command line
- Category
- Java
- Title
- how to add a number to an array in java
- Category
- Java
- Title
- java last element in array
- Category
- Java
- Title
- java http client eviction
- Category
- Java
- Title
- converting char array to string
- Category
- Java
- Title
- java regex replace all characters before
- Category
- Java
- Title
- java list to array
- Category
- Java
- Title
- biginteger in java
- Category
- Java
- Title
- java find if element of list in present in another list
- Category
- Java
- Title
- Java app development
- Category
- Java
- Title
- inheritance in java
- Category
- Java
- Title
- capcitor FERR_CLEARTEXT_NOT_PERMITTED
- Category
- Java
- Title
- height constraint layout guideline
- Category
- Java
- Title
- arraylist java methds
- Category
- Java
- Title
- islowercase java
- Category
- Java
- Title
- java calculator code
- Category
- Java
- Title
- multiplication program java
- Category
- Java
- Title
- fastapi list query parameter
- Category
- Java
- Title
- java stream sort Collator
- Category
- Java
- Title
- java getter
- Category
- Java
- Title
- getordefault java
- Category
- Java
- Title
- java how to initialize an array
- Category
- Java
- Title
- enum in java
- Category
- Java
- Title
- spigot action bar
- Category
- Java
- Title
- binary string to int java
- Category
- Java
- Title
- @JsonSerializer spring specific field string to date
- Category
- Java
- Title
- how to add objects in array java
- Category
- Java
- Title
- java execute jar from main
- Category
- Java
- Title
- split arraylist items java
- Category
- Java
- Title
- long input in JAVA
- Category
- Java
- Title
- java return new instance of generic type
- Category
- Java
- Title
- how to add a keylistener to a jframe
- Category
- Java
- Title
- how to make a text field required in android studio
- Category
- Java
- Title
- split method in java
- Category
- Java
- Title
- elasticsearch api code call using highlevelrestclient
- Category
- Java
- Title
- java nested loop
- Category
- Java
- Title
- computeifabsent hashmap java
- Category
- Java
- Title
- remove first character from string
- Category
- Java
- Title
- how to implement a interface in java
- Category
- Java
- Title
- how to make a char uppercase in java
- Category
- Java
- Title
- int to long java
- Category
- Java
- Title
- java get excectuon time
- Category
- Java
- Title
- convert java list to array
- Category
- Java
- Title
- saving String character in arraylist
- Category
- Java
- Title
- java parse xml string
- Category
- Java
- Title
- java create map
- Category
- Java
- Title
- object orientation in java
- Category
- Java
- Title
- java manacher's algorithm
- Category
- Java
- Title
- java random number generator in range
- Category
- Java
- Title
- how to check how many anagrams a word has in java
- Category
- Java
- Title
- java how to print a newline
- Category
- Java
- Title
- refrence xml textfield in javafx
- Category
- Java
- Title
- java if different ways
- Category
- Java
- Title
- how to make an array in java
- Category
- Java
- Title
- convert date to calendar java
- Category
- Java
- Title
- java while loop example
- Category
- Java
- Title
- java get int from double without rounding
- Category
- Java
- Title
- kotlin jsonobject get nested
- Category
- Java
- Title
- arraylist with values java
- Category
- Java
- Title
- how to test how many of one character is in a string java
- Category
- Java
- Title
- substring java
- Category
- Java
- Title
- read a file in java and store as integer array using buffered reader
- Category
- Java
- Title
- how to import a scanner in java
- Category
- Java
- Title
- java stream find specific element
- Category
- Java
- Title
- convert char to string java
- Category
- Java
- Title
- how to iterate hashmap in java
- Category
- Java
- Title
- java pass arraylist by value
- Category
- Java
- Title
- java how to call getReader twice
- Category
- Java
- Title
- java processbuilder example
- Category
- Java
- Title
- java get folder content
- Category
- Java
- Title
- java output length of each line in a text document
- Category
- Java
- Title
- java binary exponentiation
- Category
- Java
- Title
- how to multiply a number by itself using for loop in java
- Category
- Java
- Title
- all data types in java
- Category
- Java
- Title
- how to cut a certion part from a string in java
- Category
- Java
- Title
- java 8 validate based on pair of strings
- Category
- Java
- Title
- linux command to see all the java version installed
- Category
- Java