How to iterate a Map in Java

Posted on Updated on

There are several ways to iterate a Map in java.

  1. Iterate Map using iterator
  2. Iterate Map using keySet.
  3. Iterate Map using Entry Object.
  4. Using Lamda Expression.

Example to iterate a Map.

Output

Example 1
Key : 1 Value :New York
Key : 2 Value :London
Key : 3 Value :Paris
Key : 4 Value :Mumbai
Example 2
Key : 1 Value : New York
Key : 2 Value : London
Key : 3 Value : Paris
Key : 4 Value : Mumbai
Example 3
Key : 1 Value : New York
Key : 2 Value : London
Key : 3 Value : Paris
Key : 4 Value : Mumbai
Example 4
Key : 1 Value :New York
Key : 2 Value :London
Key : 3 Value :Paris
Key : 4 Value :Mumbai

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.