0 votes
in JAVA by
How to iterate hashmap in java?

1 Answer

0 votes
by
How to iterate hashmap in java?

import java.util.Map;

import java.util.HashMap;

  

class IterationDemo  

{

    public static void main(String[] arg)

    {

        Map<String,String> g = new HashMap<String,String>();

      

        // enter name/url pair

        g.put(""1"":""One"");

         g.put(""2"":""Two"");       

        // using for-each loop for iteration over Map.entrySet()

        for (Map.Entry<String,String> entry : g.entrySet())  

            System.out.println(""Key = "" + entry.getKey() +

                             "", Value = "" + entry.getValue());

    }

}
...