实体类排序 排序方法:sorted()
List < SellVo > records = data. getRecords ( ) ;
List < SellVo > collect1 = records. stream ( ) . sorted ( Comparator . comparing ( SellVo :: getSellAmount ( ) ) . reversed ( ) ) . collect ( Collectors . toList ( ) ) ;
map排序
List < Map < String , Object > > records = data. getRecords ( ) ;
List < Map > sellAmount = hashMaps. stream ( ) . sorted ( Comparator . comparing ( ( Map x) -> ( Integer ) x. get ( "sellAmount" ) ) . reversed ( ) ) . collect ( Collectors . toList ( ) ) ;
单条件分组 分组方法Collectors.groupingBy()
List < ShopCarVo > records = = data. getRecords ( ) ;
Map < Object , List < ShopCarVo > > collect = records. stream ( ) . map ( x -> {
return x;
} ) . collect ( Collectors . groupingBy ( o -> o. getSiteId ( ) , Collectors . toList ( ) ) ) ;
多条件分组
List < ShopCarVo > records = = data. getRecords ( ) ;
Map < Object , List < ShopCarVo > > collect = records. stream ( ) . map ( x -> {
return x;
} ) . collect ( Collectors . groupingBy ( o -> o. getSiteId ( ) + "_" + o. getBusinessId ( ) , Collectors . toList ( ) ) ) ;
map转成list;
List < List < ShopCarVo > > collect = collect. values ( ) . stream ( ) . collect ( Collectors . toList ( ) ) ;
map根据主键排序
LinkedHashMap < String , List < UserRps > > collect1 = collect. entrySet ( ) . stream ( ) . sorted ( Map. Entry . comparingByKey ( ) ) . collect ( Collectors . toMap ( Map. Entry :: getKey , Map. Entry :: getValue , ( old, now) -> old, LinkedHashMap :: new ) ) ;