List<MerchantPurchaseStat> merchantPurchaseStatList=new ArrayList<>() MerchantPurchaseStat merchantPurchaseStat = new MerchantPurchaseStat(); merchantPurchaseStat.setMerchantId(merchant.getId()); merchantPurchaseStat.setGoodsModel(bg.getModel()); merchantPurchaseStat.setBuyNum(amount); merchantPurchaseStat.setIncreaseRate(percent.multiply(BigDecimal.valueOf(100))); merchantPurchaseStat.setMarketDate(bg.getMarketDate()); merchantPurchaseStatList.add(merchantPurchaseStat); 在java中将merchantPurchaseStatList数据根据对象中buynum升序排列
时间: 2024-03-04 11:49:34 浏览: 55
List<Bean>转换为List<Map>
您可以按照以下方式实现根据对象中buynum升序排列:
```
List<MerchantPurchaseStat> sortedList = merchantPurchaseStatList.stream()
.sorted(Comparator.comparing(MerchantPurchaseStat::getBuyNum))
.collect(Collectors.toList());
```
这段代码与上面的代码非常相似,只是将reversed方法去掉了,这样就实现了升序排列。
阅读全文