将某个字段取出
List<String>ids=list.stream().map(Bean::getId).collect(Collectors.toList());
List<Bean>转Map<String,Bean>示例
GenTabletable=genTableMapper.selectGenTableByName(tableName);List<GenTableColumn>tableColumns=table.getColumns();Map<String,GenTableColumn>tableColumnMap=tableColumns.stream().collect(Collectors.toMap(GenTableColumn::getColumnName,Function.identity()));
filter过滤器使用示例
// 筛选出dataList中没有的数据List<String>filterList=addList.stream().filter(i->!dataList.contains(i)).collect(Collectors.toList());
判断是否包含
// Collection<String> authorities;booleanflag=authorities.stream().anyMatch(x->"contains".contains(x));
重新过滤List<Bean>
List<Bean>tolist=list.stream().filter(s->other.getId().equals(s.getId())).map(item->{Beanasbean=newBean();// asbean.setXx(item.getItemText());returnasbean;}).collect(Collectors.toList());
根据条件升序
// 根据条件升序List<Bean>collect=list.stream().sorted(Comparator.comparing(Bean::getOrderSort)).collect(Collectors.toList());// 根据条件降序List<Bean>collect=list.stream().sorted(Comparator.comparing(Bean::getLvl).reversed()).collect(Collectors.toList());
以逗号分隔List<Bean>中的某个字段
ids.stream().map(Bean::getXx).collect(Collectors.joining(","))
groupby特定字段
List<Bean>list=this.list(queryWrapper);Map<String,List<Bean>>allList=list.stream().collect(Collectors.groupingBy(Bean::getType));