Java Stream How to - Output one property for debug








The following code shows how to output one property for debug.

Example

/*from   w w w.ja  v a  2s  . c  o m*/
import java.util.Arrays;
import java.util.List;

public class Main {
  public static void main(String[] args) {
    List<Point> points = Arrays.asList(new Point(12, 2));
    points.stream().map(p -> p.getX()).forEach(System.out::println);
  }
}

class Point {
  private int x;
  private int y;

  public Point(int x, int y) {
    this.x = x;
    this.y = y;
  }

  public int getX() {
    return x;
  }

  public void setX(int x) {
    this.x = x;
  }
}

The code above generates the following result.