iterate through hashmap in java
Java
for (Map.Entry<String, String> entry : yourHashMap.entrySet()) {
System.out.println(entry.getKey() + " = " + entry.getValue());
}// Java program to traverse through
// a hashmap using iterator
import java.util.*;
class GfG {
public static void main(String[] args)
{
// Consider the hashmap contains
// 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);
// Getting an iterator
Iterator hmIterator = hm.entrySet().iterator();
// Iterate through the hashmap
// and add some bonus marks for every student
System.out.println("HashMap after adding bonus marks:");
while (hmIterator.hasNext()) {
Map.Entry mapElement = (Map.Entry)hmIterator.next();
int marks = ((int)mapElement.getValue() + 10);
System.out.println(mapElement.getKey() + " : " + marks);
}
}
}
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}// 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
- JSONObject java
- Category
- Java
- Title
- object orientation in java
- Category
- Java
- Title
- set password visible in android
- Category
- Java
- Title
- java map print
- Category
- Java
- Title
- 2d arrays | java
- Category
- Java
- Title
- java min function
- Category
- Java
- Title
- read and write files pattern java
- Category
- Java
- Title
- how to create a JFrame in java
- Category
- Java
- Title
- how to detect device javascirpt
- Category
- Java
- Title
- big integer java
- Category
- Java
- Title
- pascals triangle java
- Category
- Java
- Title
- java string length validation regex
- Category
- Java
- Title
- java - a program to print open ports
- Category
- Java
- Title
- how to check the end of a string java
- Category
- Java
- Title
- how to crate a list in java script
- Category
- Java
- Title
- iterate through hashtable java
- Category
- Java
- Title
- get today date in java 8
- Category
- Java
- Title
- java list contains object with property
- Category
- Java
- Title
- sort array java
- Category
- Java
- Title
- java startActivity crash
- Category
- Java
- Title
- how do you concatenate an int with a string in java
- Category
- Java
- Title
- java optional to collection
- Category
- Java
- Title
- java linked list iterator
- Category
- Java
- Title
- override java
- Category
- Java
- Title
- java random number in range
- Category
- Java
- Title
- islowercase java
- Category
- Java
- Title
- read lines of file randomly java
- Category
- Java
- Title
- actionListener java
- Category
- Java
- Title
- iterator for array java
- Category
- Java
- Title
- recursion in java
- Category
- Java
- Title
- kotlin vs java
- Category
- Java
- Title
- python vs java
- Category
- Java
- Title
- binary to int java
- Category
- Java
- Title
- change fab image programatically
- Category
- Java
- Title
- formartted string java
- Category
- Java
- Title
- install java debian 8
- Category
- Java
- Title
- StringBuilder java pop back
- Category
- Java
- Title
- how to loop through an array
- Category
- Java
- Title
- java lerp
- Category
- Java
- Title
- java swing timer sleep
- Category
- Java
- Title
- java map foreach
- Category
- Java
- Title
- switch en java
- Category
- Java
- Title
- how to use spring in java
- Category
- Java
- Title
- how to make a minecraft hacked client drawing the hud malicious intent
- Category
- Java
- Title
- how to convert string to double in android studio
- Category
- Java
- Title
- rewrite file java
- Category
- Java
- Title
- convert char to string java
- Category
- Java
- Title
- java get icon for file type
- Category
- Java
- Title
- annotation spring notnull
- Category
- Java
- Title
- capcitor FERR_CLEARTEXT_NOT_PERMITTED
- Category
- Java
- Title
- sort elements with sortedset
- Category
- Java
- Title
- org.springframework.orm.jpa.EntityManagerHolder cannot be cast to org.springframework.orm.hibernate5.SessionHolder
- Category
- Java
- Title
- array of objects in java
- Category
- Java
- Title
- primitive data types in java
- Category
- Java
- Title
- java string reverse
- Category
- Java
- Title
- java replace all xml decoding
- Category
- Java
- Title
- java public private key encryption
- Category
- Java
- Title
- reverse array in java
- Category
- Java
- Title
- bracket balancing program in java
- Category
- Java
- Title
- change brightness of image in java
- Category
- Java
- Title
- how to get the dimensions of a 2d array in java
- Category
- Java
- Title
- java lambda list of objects cast
- Category
- Java
- Title
- java script zip function
- Category
- Java
- Title
- official java website
- Category
- Java
- Title
- java print type of object
- Category
- Java
- Title
- fibonacci sequence in java recursion
- Category
- Java
- Title
- java jaxb unmarshall xml to map
- Category
- Java
- Title
- java string to int
- Category
- Java
- Title
- hide element selenium
- Category
- Java
- Title
- java 8 validate based on pair of strings
- Category
- Java
- Title
- java set example
- Category
- Java
- Title
- int to binary java
- Category
- Java
- Title
- online money transfer andhra bank
- Category
- Java
- Title
- how to add a number to an array in java
- Category
- Java
- Title
- create java windows application
- Category
- Java
- Title
- print a list java
- Category
- Java
- Title
- applicationcontext.xml
- Category
- Java
- Title
- how to read in a file in java
- Category
- Java
- Title
- date to string java
- Category
- Java
- Title
- how to create a thread local variable in java
- Category
- Java
- Title
- change fragment in android studio
- Category
- Java
- Title
- java iterator example
- Category
- Java
- Title
- how do you make a method that returns an array java
- Category
- Java
- Title
- java return new instance of generic type
- Category
- Java
- Title
- int java
- Category
- Java
- Title
- mutable string in java
- Category
- Java
- Title
- reverse string using recursion java with explanation
- Category
- Java
- Title
- query java persistence
- Category
- Java
- Title
- java get current date without time
- Category
- Java
- Title
- springBoot
- Category
- Java
- Title
- dates in java 8
- Category
- Java
- Title
- get sha key android
- Category
- Java
- Title
- java string to double
- Category
- Java
- Title
- how to create a method java
- Category
- Java
- Title
- java singleton implementation
- Category
- Java
- Title
- isSelfDivisor java
- Category
- Java
- Title
- java loop through object
- Category
- Java
- Title
- inline foreach java
- Category
- Java
- Title
- ecommerce app github android
- Category
- Java
- Title
- java file exists
- Category
- Java