Reputation: 1
We are getting list of AssetValue from database,
After getting the list I need to group by id and sort by year and month.
Based on the grouping I need to print on reports.
Public Class AssestValue{
private String Date;
Private String Year;
Private Idvalue idvalue;
--Getter and Setters
}
Public Class IdValue{
private String id;
}
I know to do this in Java 7 , but I need to know how to achieve this in Java 8 Streams.
I need to identify how to achieve this in Java streams
Upvotes: -6
Views: 57
Reputation: 37
Map<IdValue, List<AssestValue>> groupbyAns = assetValues.stream().collect(Collectors.groupingBy(assestValue -> assestValue.getIdvalue()));
groupbyAns.forEach((idValue, assestValues) -> assestValues
.sort(Comparator.comparingInt((AssestValue o) -> Integer.parseInt(o.getYear()))
.thenComparing((AssestValue o1) -> Integer.parseInt(o1.getDate()))));
Upvotes: 0