How to Iterate HashMap

0 votes
can you please help me with the code? How to iterate HashMap?
May 30, 2019 in Java by Shashank
805 views

1 answer to this question.

0 votes

Hi Shashank.

Please try this code I hope it will help you out 

for (Map.Entry<String, Object> entry : map.entrySet()) {
    String key = entry.getKey();
    Object value = entry.getValue();
    System.out.println(key); System.out.println(value);}
answered May 30, 2019 by sampriti
• 1,120 points

Related Questions In Java

0 votes
1 answer

How to convert or cast hashmap to JSON object in Java, and again convert JSON object to JSON string?

You can use: new JSONObject(map); READ MORE

answered Jun 27, 2018 in Java by Akrati
• 3,190 points
6,990 views
0 votes
1 answer

How to directly initialize a HashMap?

Hello @Kartik, In plain java 8 you also ...READ MORE

answered Jul 28, 2020 in Java by Niroj
• 82,840 points
1,233 views
0 votes
0 answers

How to iterate arraylist in java?

How does one perform iteration over an ...READ MORE

Dec 19, 2023 in Java by Saniya
• 3,360 points
458 views
+5 votes
4 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,450 points

edited Nov 7, 2018 by Omkar 81,195 views
+1 vote
1 answer

Are arrays equivalent to objects in Java ?

Yes; the Java Language Specification writes: In the Java ...READ MORE

answered May 10, 2018 in Java by Rishabh
• 3,620 points
1,319 views
+1 vote
1 answer

Remove objects from an array in Java?

We can use external libraries: org.apache.commons.lang.ArrayUtils.remove(java.lang.Object[] array, int ...READ MORE

answered Jun 26, 2018 in Java by scarlett
• 1,290 points
1,178 views
+1 vote
1 answer

Performance difference of if/else vs switch statement in Java

The thing you are worried about is ...READ MORE

answered Jul 26, 2018 in Java by geek.erkami
• 2,680 points
3,734 views
0 votes
2 answers

How to iterate in a HashMap in Java?

Iterating using Iterator. Using Generics: Map<Integer, Integer> map = ...READ MORE

answered Aug 28, 2019 in Java by Sirajul
• 59,230 points
1,016 views
0 votes
1 answer

how to compare two words in java?

hey,  I think in your code the function ...READ MORE

answered Aug 8, 2019 in Java by sampriti
• 1,120 points

edited Aug 8, 2019 by Kalgi 2,259 views
0 votes
1 answer

How to add items in list at a time?

Hi Priyanka , I think this code snippet ...READ MORE

answered Aug 9, 2019 in Java by sampriti
• 1,120 points
2,379 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP