“java 8 peta foreach” Kode Jawaban

peta foreach java

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

Java Foreach Map

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

java 8 peta foreach

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

java 8 peta 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 peta foreach

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

java 8 peta 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

Jawaban yang mirip dengan “java 8 peta foreach”

Pertanyaan yang mirip dengan “java 8 peta foreach”

Lebih banyak jawaban terkait untuk “java 8 peta foreach” di Java

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya