public static void main(String[] args) {
List<OrderInfo> orderList = new ArrayList<>();
OrderInfo orderInfo = new OrderInfo();
orderInfo.setOrderNo(null);
OrderInfo orderInfo2 = new OrderInfo();
orderInfo2.setOrderNo("123");
OrderInfo orderInfo3 = new OrderInfo();
orderInfo3.setOrderNo("222");
orderList.add(orderInfo);
orderList.add(orderInfo2);
orderList.add(orderInfo3);
// ---------------------------------------------------------------
orderList = orderList.stream()
.filter( //篩選
// o -> o.getOrderNo() != null
o -> {
if (o.getOrderNo() != null) {
return true;
} else {
return false;
}
}
)
.map(o -> {
// o.setOrderNo(o.getOrderNo() + "----");
return o;
})
.sorted((o1,o2) -> { //設值
Integer oo1 = Integer.parseInt(o1.getOrderNo());
Integer oo2 = Integer.parseInt(o2.getOrderNo());
return oo2.compareTo(oo1);
})
.limit(1) //幾個之前
.collect(Collectors.toList());
// 走訪
orderList.stream().forEach(o -> System.out.println(o.getOrderNo()));
orderList.parallelStream().forEach(o -> System.out.println(o.getOrderNo())); //有順序的
}