1. 属性に基づいてリストをフィルタリングする
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. リストを正の順序と逆の順序に並べます
//正序排列
Collections.sort(s);
//倒序排列(先对list正序排列,然后反向排序)
Collections.sort(s);
Collections.reverse(s);//反向排序
ラムダ式の関連する基本については、を参照してください。
https://my.oschina.net/u/4006148/blog/3078359