Java Map for each with Lambda expression

Description

Java Map for each with Lambda expression


import java.util.HashMap;
import java.util.Map;

public class Main {
  public static void main(String[] args) {
    Map<Integer, String> map = new HashMap<>();

    for (int i = 0; i < 10; i++) {
      map.put(i, "Value " + i);
    }/*w  ww. jav  a 2  s  .c om*/
    System.out.println(map);
    
    map.forEach((id, val) -> System.out.println(val));
    
  }
}



PreviousNext

Related