JavaListStream流,去空,字段赋值,去重Java List Stream流,去空,字段赋值,去重
1.实体类
/**
* @description ⽤户
* @author ln
*/
@Data
public class User {
private String id;
private String name;
private String nickname;
private String sex;
private String age;
private String type;
}
2.去空
public void removeEmpty(){
List<User> userList=new ArrayList<>();
userList.add(new("1","⽤户1","yonghu1","⼥","22","0"));
userList.add(new("2","⽤户2","yonghu2","男","24","0"));
userList.add(new("3","⽤户3","yonghu3","⼥","24","0"));
userList.add(new("4","⽤户4","yonghu4","男","23","0"));
List<User> list= userList.stream()
.filter(User -> Id()!=null && Name()!=null)
.List());
}
3.赋值
public void setValue(){
List<User> userList=new ArrayList<>();
userList.add(new("1","⽤户1","yonghu1","⼥","22","0"));
userList.add(new("2","⽤户2","yonghu2","男","24","0"));
userList.add(new("3","⽤户3","yonghu3","⼥","24","0"));
java streamuserList.add(new("4","⽤户4","yonghu4","男","23","0"));
List<User> list= userList.stream()
.map(object ->{
User user =new User();
user.setType("1");
return user;
})
.List());
}
4.去重
public void removeRepeat(){
List<User> userList=new ArrayList<>();
userList.add(new("1","⽤户1","yonghu1","⼥","22","0"));
userList.add(new("2","⽤户2","yonghu2","男","24","0"));
userList.add(new("3","⽤户3","yonghu3","⼥","24","0"));
userList.add(new("4","⽤户4","yonghu4","男","23","0"));
// 去重
userList= userList.stream().collect(
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论