Java对象类型集合单独取出对象中一个属性成为集合或数组
集合
List<DictEntity> dictEntityList = dictService.findByType(6);
1
取出属性为集合
List<String> stateNameList = dictEntityList.stream().map(DictEntity::getName).collect(Collectors.toList());
1
取出属性为数组
Long[] ids = dictEntityList.stream().map(DictEntity::getId).toArray(Long[]::new);
1
集合去重
dictEntityList.stream().distinct().collect(Collectors.toList());
原文链接:https://blog.csdn.net/zmz200225/article/details/109000400