将Restriction对象中的value属性取出并逗号拼接
String str = restrictionList.stream().map(Restriction::getValue).collect(Collectors.joining(","));
将Restriction对象中的id属性逗号拼接后转换为Strnig类型
String str = restrictionList.stream().map(Restriction::getId).collect(Collectors.toList()).stream().map(w->w.toString()).collect(Collectors.joining(","));
去重
// 根据name去重
List<Person> unique = persons.stream().collect(
collectingAndThen(
toCollection(() -> new TreeSet<>(comparing(Person::getName))), ArrayList::new)
);
// 根据name,sex两个属性去重
List<Person> unique = persons.stream().collect(
collectingAndThen(
toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getName() + ";" + o.getSex()))), ArrayList::new)
);
根据FullName和CancelTime筛选
List<BlacklistUser> buList = SystemInitVariable.blacklistUserList.stream().filter(bu ->
bu.getUsername().equals(us.getFullName()) && bu.getCancelTime().after(currentTime)
).collect(Collectors.toList());
将字符串集合中的数据批量下划线分隔
Set strs =new HashSet<>();
strs.add("a_a");
strs.add("b_b");
strs.add("c_c");
Set strsss = strs.stream().map(str -> str.substring(str.indexOf("_")+1)).collect(Collectors.toSet());