public class Djmxlist {
private String dxmc;
private Integer sl;
public String getDxmc() {
return dxmc;
}
public void setDxmc(String dxmc) {
this.dxmc = dxmc;
}
public Integer getSl() {
return sl;
}
public void setSl(Integer sl) {
this.sl = sl;
}
}
插入一下数据
List<Djmxlist> list=new ArrayList<>();
for (int i = 1; i < 4; i++) {
Djmxlist mx=new Djmxlist();
mx.setDxmc("名称"+i);
mx.setSl(i);
list.add(mx);
}
Djmxlist mx1=new Djmxlist();
mx1.setDxmc("名称"+1);
mx1.setSl(1);
list.add(mx1);
Stream流的一些用法
int min=list.stream().mapToInt(Djmxlist::getSl).min().getAsInt();
int max=list.stream().mapToInt(Djmxlist::getSl).max().getAsInt();
int first=list.stream().mapToInt(Djmxlist::getSl).findFirst().getAsInt();
List<Djmxlist> list1=list.stream().distinct().collect(Collectors.toList());;
List<Djmxlist> list2=list.stream().filter(u->u.getSl()>2).collect(Collectors.toList());
int zsl=list.stream().mapToInt(Djmxlist::getSl).sum();