I have lists:
List<Point[]> listPoints = ...
List<Quadrangle> quadrangles = ...
How convert List<Point[]> to List<Quadrangle> with Stream in Java 8?
Need replace:
for(Point[] groupPoints : listPoints) {
quadrangles.add(new Quadrangle(groupPoints));
}
Object Quadrangle has the constructor:
public Quadrangle(Point[] points) {
this.p1 = points[0];
this.p2 = points[1];
this.p3 = points[2];
this.p4 = points[3];
}
I tried this:
List<Quadrangle> quadrangles = listPoints.stream()
.collect(Collectors.toCollection(o -> new Quadrangle(o)));
but this doesn't work for me. I get error:
Required type:Point[]
Provided: <lambda parameter>
I thought that the lambda parameter o is the array Point [], but isn't it.