ITERATE OVER EACH ENTRY IN A MAP

Pravesh Singh

Total Post:412

Points:2888
Posted by  Pravesh Singh
Java 
 803  View(s)
Ratings:
Rate this:

If I have an object implementing the MAP interface in Java and I wish to iterate over every pair contained within it, what is the most efficient way of going through the map?

Will the ordering of elements depend on the specific map implementation that I have for the interface?

  1. Mayank Tripathi

    Post:397

    Points:3117
    Re: Iterate over each Entry in a Map

    for (Map.Entry<String, String> entry : map.entrySet())
    {
        System.out.println(entry.getKey() + "/" + entry.getValue());
    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!