list对象根据ID个字段转为list<String>
List<UserEntity> userEntitys=new ArrayList<>();
List<String> list =userEntitys.stream().map(UserEntity::getId).collect(Collectors.toList());
根据id字段来去重并且吧account这个值用逗号拼接起来,拿到是去重并且吧account凭借出来的一个对象
List<UserEntity> list=new ArrayList<>();
UserEntity entity1=new UserEntity();
entity1.setId("1");
entity1.setAccount("嘿嘿饿");
list.add(entity1);
UserEntity entity2=new UserEntity();
entity2.setId("1");
entity2.setAccount("嘿嘿");
list.add(entity2);
list= new ArrayList<>(list.stream()
// 表示name为key,接着如果有重复的,那么从Pool对象o1与o2中筛选出一个,这里选择o1,
// 并把name重复,需要将value与o1进行合并的o2, 赋值给o1,最后返回o1
.collect(Collectors.toMap(UserEntity::getId, a -> a, (o1, o2) -> {
o1.setAccount(o1.getAccount() + "," + o2.getAccount());
return o1;
})).values());
System.err.println(list);
把list对象转化为map key为id value为对应的对象
Map<String, UserEntity> collect = list.stream().collect(Collectors.toMap(UserEntity::getId, account -> account));
list对象转化为map key 和value都为制定字段
Map<String, String> collect = list.stream().collect(Collectors.toMap(UserEntity::getId, UserEntity::getAccount, (oldValue, newValue) -> newValue));
list对象 判断对象中的某一个值 然后取出 其他字段转化为list<String
// 假设你有一个名为objects的对象数组
YourObject[] objects = {
new YourObject("uuid1", 0),
new YourObject("uuid2", 1),
new YourObject("uuid3", 0),
new YourObject("uuid4", 0)
};
// 找出state字段为0的对象,并将uuid字段转化为List<String>
List<String> uuidList = Arrays.stream(objects)
.filter(obj -> obj.getState() == 0)
.map(YourObject::getUuid)
.collect(Collectors.toList());