How to Iterate Through Java MAP in Android

In this article, we will learn how to Iterate through Java MAP in Android Studio.

First, we cannot iterate a map directly using iterators because maps are not collections. Before you go any further, you should also know a little about the Map.Entry interface.
Since all maps in Java implement the map interface, the following techniques will work for any map implementation (HashMap, TreeMap, LinkedHashMap, Hashtable, etc.)

Below is the code how to Iterate through Java MAP

Map<String, String> map = ...
for (Map.Entry<String, String> entry : map.entrySet()) {
    System.out.println(entry.getKey() + "/" + entry.getValue());
}

On Java 10+

for (var entry : map.entrySet()) {
System.out.println(entry.getKey() + "/" + entry.getValue());
}

Next Article

1. View Profile Activity in Android Studio – Kotlin & Java

Please share this post:
Posts created 60

Ask a Question

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

%d bloggers like this: