1.根據屬性過濾list
List<AllManagerBean> testLists = broadCastRoomMapper.allManagerlist();
List<AllManagerBean> mans = testLists.stream().filter(j->j.getRoomId().equals(roomid)).collect(Collectors.toList());
//過濾某一屬性,成一個新集合
List<String> uids = testLists.stream().map(e->e.getUserid()).collect(Collectors.toList());
2.遍歷集合
List<ManagerBean> managerListNew = new ArrayList<ManagerBean>();
if (mans != null ){
mans.forEach(man->{
managerListNew.add(man);
});
}
3.根據某一集合對象中的某一屬性,排序
List<Model> thlistbysort = thlist.stream().sorted(Comparator.comparing(Model::getSort)).collect(Collectors.toList()); //正序
List<Model> thlistbysort = thlist.stream().sorted(Comparator.comparing(Model::getSort).reversed()).collect(Collectors.toList()); //倒序
4.對List<String>進行正序,倒序排列
//正序排列
Collections.sort(s);
//倒序排列(先對list正序排列,然后反向排序)
Collections.sort(s);
Collections.reverse(s);//反向排序
關於lanbda表達式相關基礎可參考