Ho do I Iterate through a HashMap which contains duplicate values

0 votes
What is the fastest and the best way to iterate over the elements of a HashMap.
Apr 16, 2018 in Java by Daisy
• 8,050 points
170 views

2 answers to this question.

0 votes

Entry-set is iterated as :

public static void printMaps(Map map) {
    Iterator itr = map.entrySet().iterator();
    while (itr.hasNext()) {
        Map.Entry pairs = (Map.Entry)itr.next();
        System.out.println(pairs.getKey() + " = " + pairs.getValue());
        itr.remove(); //  ConcurrentModificationException is avoided
    }
}
answered Apr 16, 2018 by anonymous
0 votes
for (Map.Entry<String, String> item : params.entrySet()) {
    String key = item.getKey();
    String value = item.getValue();
}
answered Jul 24, 2018 by samarth295
• 2,190 points

Related Questions In Java

0 votes
0 answers

Ho do I Iterate through a HashMap which contains duplicate values

What is the fastest and the best ...READ MORE

Apr 16, 2018 in Java by Daisy
• 8,050 points
60 views
0 votes
1 answer

How do I fix a NullPointerException?

When you declare a reference variable (i.e. ...READ MORE

answered Apr 13, 2018 in Java by parth295
• 4,640 points
96 views
0 votes
1 answer

How do I create a Java string from the contents of a file?

If you're looking for an alternative that ...READ MORE

answered Apr 19, 2018 in Java by Rishabh
• 3,540 points
99 views
0 votes
2 answers
0 votes
1 answer

HashMap vs LinkedHashMap vs TreeMap

Hi, there is no as such difference ...READ MORE

answered May 4, 2018 in Java by v.liyyah
• 1,300 points
276 views
0 votes
2 answers

Performing Iteration over each entry in a 'Map'

In Java 8 you can do it ...READ MORE

answered Oct 24, 2018 in Java by Sushmita
• 6,880 points
56 views
0 votes
2 answers
0 votes
1 answer

How can I Sort an ArrayList in Java

You can sort the ArrayList in 2 ...READ MORE

answered Apr 23, 2018 in Java by sharth
• 3,350 points
70 views
0 votes
2 answers

How can I get the filenames of all files in a folder which may or may not contain duplicates

List<String> results = new ArrayList<String>(); File[] files = ...READ MORE

answered Sep 12, 2018 in Java by Sushmita
• 6,880 points
610 views
0 votes
2 answers

How can I create File and write data in it using Java?

import java.io.BufferedWriter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; public class WriteFiles{ ...READ MORE

answered Jul 26, 2018 in Java by samarth295
• 2,190 points
108 views