public class Test {
String a;
String b;
String c;
public Test ok(String a,String b,String c){
Test t = new Test();
t.setA(a);
t.setB(b);
t.setC(c);
return t;
}
public String getA() {
return a;
}
public void setA(String a) {
this.a = a;
}
public String getB() {
return b;
}
public void setB(String b) {
this.b = b;
}
public String getC() {
return c;
}
public void setC(String c) {
this.c = c;
}
public static void main(String[] args) {
List<Test> list = new ArrayList<>();
list.add(new Test().ok("1","2","3"));
list.add(new Test().ok("5","0","5"));
list.add(new Test().ok("3","1","6"));
list.add(new Test().ok("8","5","3"));
list.add(new Test().ok("3","7","8"));
List<String> list1 = list.stream().map(Test::getA).distinct().collect(Collectors.toList());
System.out.println(list1);
List<String> list2 = list.stream().map(Test::getB).distinct().collect(Collectors.toList());
System.out.println(list2);
List<String> list3 = list.stream().map(Test::getB).distinct().filter(s -> !StringUtils.equals(s,"5")).collect(Collectors.toList());
System.out.println(list3);
}
}
输出:
[1, 5, 3, 8]
[2, 0, 1, 5, 7]
[2, 0, 1, 7]