JDK8 取实体类最大最小值

List<SrmSfdBidItemVO> testList = new ArrayList<>();
SrmSfdBidItemVO testLine=new SrmSfdBidItemVO();
testLine.setItemCode("AB");
testLine.setNoTaxPrice(new BigDecimal("324"));
testList.add(testLine);
SrmSfdBidItemVO testLine1=new SrmSfdBidItemVO();
testLine1.setItemCode("ABD");
testLine1.setNoTaxPrice(new BigDecimal("315"));
testList.add(testLine1);
SrmSfdBidItemVO testLine2=new SrmSfdBidItemVO();
testLine2.setItemCode("ABD");
testLine2.setNoTaxPrice(new BigDecimal("424"));
testList.add(testLine2);
SrmSfdBidItemVO testLine3=new SrmSfdBidItemVO();
testLine3.setItemCode("ABE");
testLine3.setNoTaxPrice(new BigDecimal("214"));
testList.add(testLine3);
//最小值
SrmSfdBidItemVO minBidItem = testList.stream().min(Comparator.comparing(SrmSfdBidItemVO::getNoTaxPrice)).get();
System.out.println("minBidItem:"+minBidItem.getNoTaxPrice());
//最大值
SrmSfdBidItemVO maxBidItem = testList.stream().max(Comparator.comparing(SrmSfdBidItemVO::getNoTaxPrice)).get();
System.out.println("maxBidItem:"+maxBidItem.getNoTaxPrice());

 

posted @ 2021-02-01 10:43  哎丫丫呀喂  阅读(550)  评论(0编辑  收藏  举报