1、islegal函数返回false,则list中过滤掉。
List<Student> result = list.stream().filter(w -> islegal(w.getName(),illegal)).collect(Collectors.toList());
2、
Set<String> ids = list.stream().map(Student::getId).collect(Collectors.toSet());
List<Long> ids = list.stream().map(Student::getId).collect(Collectors.toList());
List<HxUserMapping> mappings = ....;
Map<Long, String> map = mappings.stream().collect(Collectors.toMap(HxUserMapping::getUserId, HxUserMapping::getHxUserId));
如果list里面有重复的数据,to map 会报错,所以可以使用下面的方式:
Map<Long,String> map3 = list.stream().collect(Collectors.toMap(HxUserMapping::getUserId, HxUserMapping::getHxUserId, (key1, key2) -> key2));
3.
List<HxLoan> result = hxLoans.stream().filter(w -> isNotIn(w.getLoanId(),wdLoanIds)).collect(Collectors.toList());
private boolean isNotIn(Long loanId, List<Long> loanIds) {
if(loanIds.contains(loanId)) return false;
return true;
}
//返回false则被过滤掉