常用代码汇编
获取某个list属性的值(采用Java8的Optional避免空)
List students = Optional.ofNullable(condition.getStudents()).orElse(new ArrayList<>());
为某个set属性赋值
man.setValues(Stream.of(“123”,“456”,“789”).collect(Collectors.toSet()));
为某个List属性赋值
Info.setValues(Arrays.asList(“123”,“456”,“789”));
为单个值的List属性赋值
info.setValues(Collections.singletonList(new Item(“name”, “xiaoming”)));
使用Stream流处理数据
Set set = list.stream()
.map(Student::getItem)
.filter(Objects::nonNull)
.map(String::toLowerCase)
.collect(Collectors.toSet());