实体类
public class Sp {
String spdm;
String spmc;
public Sp() {
}
public Sp(String spdm, String spmc) {
this.spdm = spdm;
this.spmc = spmc;
}
public String getSpdm() {
return spdm;
}
public void setSpdm(String spdm) {
this.spdm = spdm;
}
public String getSpmc() {
return spmc;
}
public void setSpmc(String spmc) {
this.spmc = spmc;
}
}
list
public static void main(String[] args) {
List<Sp> sps=new ArrayList<>();
Sp sp1=new Sp("01","商品1");
Sp sp2=new Sp("02","商品2");
Sp sp3=new Sp("03","商品3");
Sp sp4=new Sp("04","商品4");
Sp sp5=new Sp("05","商品5");
sps.add(sp1);
sps.add(sp2);
sps.add(sp3);
sps.add(sp4);
sps.add(sp5);
List<String> spdms=sps.stream().map(u->u.getSpdm()).collect(Collectors.toList());
System.out.println(spdms);
}
结果