I've a a stream which I want to partition into smaller parts based on matching Id and then apply some proccessing logic on each of the part/element.
class BigRequest{
String bId;
List<Parts> parts;
//getters and setter here
}
Class Parts{
String pId;
String partId;
//getters and setter here
}
I want to segregate and create a list of Parts of size 10 when the partId of different parts are same.
How to use the filter or reduce or groupingBy function to compare the two elements and put them to a list? I've tried filter like below, doesn't take p1 variable:
big.stream().filter( p -> p.getPartId() == p1.getPartId()) //error
Tried groupingBy like this
big.stream().collect(Collectors.groupingBy(Parts::getPartId) //error
I want to iterate over the filtered/reduced list a another and call another function called abc(). How can I do it using Java Streams?
pseudo:
big.getParts().stream.
//dividing logic logic
for(i < parts.size)
abc(p)
Thanks
BigRequest, yet you are callingParts::getPartIdon it, which is the same as callingBigRequest.getPartId()(not going to work). You will have toflatMap(bigParts -> bigParts.parts.stream())and then it'll allow you to useParts::getPartId.Stream<T>into some kind ofStream<List<T>>- streams are by design operations on only single element at a time. You can unwrapStream<List<T>>into aStream<T>, but the opposite is not available for you.