Can we loop over a map using size and for loop
<p>I've the below code.</p>

<pre><code>String[] guest1 = { "surfing", "yoga", "walking" };
String[] guest2 = { "wine", "relaxation", "beach" };

ArrayList&lt;String&gt; list1 = new ArrayList&lt;&gt;();
list1.add("museums");
list1.add("canals");
list1.add("nightlife");
list1.add("walking");
ArrayList&lt;String&gt; list2 = new ArrayList&lt;&gt;();
list2.add("beach");
list2.add("surfing");
list2.add("relaxation");
ArrayList&lt;String&gt; list3 = new ArrayList&lt;&gt;();
list3.add("surfing");
list3.add("nightlife");
list3.add("beach");
list3.add("food");
list3.add("wine");
list3.add("walking");

String[] sagres = { "beach", "surfing", "relaxation" };
String[] biarritz = { "surfing", "nightlife", "beach", "food", "wine", "walking" };

Map map = new HashMap&lt;String, ArrayList&lt;String&gt;&gt;();
map.put("amsterdam", list1);
map.put("sagres", list2);
map.put("biarritz", list3);

for (int i = 0; i &lt; map.size(); i++) {
    System.out.println(map.keySet());
}
</code></pre>

<p>Here I'm trying to get the key and the values by looping on the size.</p>

<p>I know that this can be done using </p>

<pre><code>for (Object keys : map.keySet().toArray()) {
    System.out.println(keys);
}
</code></pre>

<p>But I have to compare 2 values at a time and work accordingly. I want to know if I can use the <code>size</code> and loop.</p>

<p>Thanks</p>