Is there a way to combine the following 2 statements?
Map<Integer,Double> collX = listeAllerPunkte.stream().collect(groupingBy(DataPoint::getId,
averagingDouble(DataPoint::getX)));
Map<Integer,Double> collY = listeAllerPunkte.stream().collect(groupingBy(DataPoint::getId,
averagingDouble(DataPoint::getY)));
I have a class DataPointsas follows:
public class DataPoint {
public final double x;
public final double y;
private int Id;
public DataPoint(double x, double y) {
this.x = x;
this.y = y;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public int getId() {
return Id;
}
}
Idcontains a random value between 0-5.
listeAllerPunkteis Listwith a lot ofDataPoints
Now I want to create DataPointfor everyone DataPointsin the List with the same Id. DataPointshould have a mean value of x and y valuesdatapoints with the same Id.
With two Statemantes from the Beginning, I have to create DataPointsmanually from two Maps. Is there a way to create them directly in the stream?
Kevin source
share