Advertisement
Guest User

List of shapes (Lambda Expressions)

a guest
Oct 16th, 2014
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.44 KB | None | 0 0
  1. List<Shape> shapes = new ArrayList<Shape>(){};
  2.         shapes.add(rect);
  3.         shapes.add(circle);
  4.         shapes.add(tri);
  5.         shapes.add(piramyd);
  6.         shapes.add(cuboid);
  7.         shapes.add(sphere);
  8. List<Shape> orderdByVolume = shapes.stream()
  9.                 .filter(s -> s instanceof VolumeMeasurable)
  10.                 .filter(v -> ((VolumeMeasurable) v).getVolume() > 40)
  11.                 .collect(Collectors.toList());
  12.         for (Shape shape : orderdByVolume) {
  13.             System.out.println(shape);
  14.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement