Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

map.keySet

/**Here, the loop iterates over keySet. 
For each key, we get the corresponding value using Map.get.
While this is an obvious way to use all of the entries in the map,
it requires two operations for each entry — one to get the next key and one 
to look up the value with get.
If we need just the keys in a map,
keySet is a good option. However, there's a faster way to 
get both the keys and values. **/
for (String key : bookMap.keySet()) {
    System.out.println("key: " + key + " value: " + bookMap.get(key));
}
Source by www.baeldung.com #
 
PREVIOUS NEXT
Tagged:
ADD COMMENT
Topic
Name
1+7 =