Set key1 = map.keySet(); Iterator it1 = key1.iterator(); int cnt=0; while (it1.hasNext()) { cnt++; }
What are the chances that this code will result
Yes. Until you don't call it1.next() it will never move on to next item. Beause it1.next() will return the object which you have added in the list/set.
it1.next()