1.

Can We Iterate Through A Map?

Answer»

Though we can't ITERATE a MAP as such but Map interface has methods which provide a set view of the Map. That set can be iterated. Those two methods are -

  • Set<Map.Entry<K, V>>entrySet() - This METHOD returns a set that contains the entries in the map. The entries in the set are actually object of type Map.Entry.
  • Set<K>KEYSET() - This method returns a set that contains the keys of the map.

There is also a values() method in the Map that returns a Collection view of the values CONTAINED in this map.

Though we can't iterate a Map as such but Map interface has methods which provide a set view of the Map. That set can be iterated. Those two methods are -

There is also a values() method in the Map that returns a Collection view of the values contained in this map.



Discussion

No Comment Found