“Java foreach Karte” Code-Antworten

foreach map java

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

Java foreach Karte

map.forEach((k, v) -> System.out.printf( " %s : %d \n" , k,v) );
Pable Sorren

Java 8 Karte foreach

public void iterateUsingStreamAPI(Map<String, Integer> map) {
    map.entrySet().stream()
      // ...
      .forEach(e -> System.out.println(e.getKey() + ":" + e.getValue()));
}
Tense Turtle

Java 8 Karte foreach

public void iterateUsingEntrySet(Map<String, Integer> map) {
    for (Map.Entry<String, Integer> entry : map.entrySet()) {
        System.out.println(entry.getKey() + ":" + entry.getValue());
    }
}
Powerful Pelican

Java 8 Karte foreach

public void iterateUsingLambda(Map<String, Integer> map) {
    map.forEach((k, v) -> System.out.println((k + ":" + v)));
}
Powerful Pelican

Java 8 Karte foreach

public void iterateUsingIteratorAndEntry(Map<String, Integer> map) {
    Iterator<Map.Entry<String, Integer>> iterator = map.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<String, Integer> entry = iterator.next();
        System.out.println(entry.getKey() + ":" + entry.getValue());
    }
}
Powerful Pelican

Ähnliche Antworten wie “Java foreach Karte”

Fragen ähnlich wie “Java foreach Karte”

Weitere verwandte Antworten zu “Java foreach Karte” auf Java

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen