public class Test {
public static void main(String[] args) {
Stream<String> ss=Stream.of("aaa","bbb","aaa","ccc").distinct();
List<String> hh=ss.collect(Collectors.toList());
System.out.println(hh);
}
}
得到的值为:[aaa, bbb, ccc]
方法二:
public class Test {
public static void main(String[] args) {
List<String> aa=new ArrayList();
aa.add("aaa");
aa.add("bbb");
aa.add("aaa");
aa.add("ccc");
System.out.println("原始值:"+aa);
List<String> bb=aa.stream().distinct().collect(Collectors.toList());
System.out.println("过滤后的值:"+bb);
}
}
得到的值为:
原始值:[aaa, bbb, aaa, ccc]
过滤后的值:[aaa, bbb, ccc]