1:取list集合某个属性的值集合
List<FanRoomSpell> spellList01 = fanRoomSpellMapper.selectFanRoomSpellList(fanRoomSpell);
//getStudentId是获取该属性值,FanRoomSpell是此对象
List<String> studentId01 = spellList01.parallelStream().map(FanRoomSpell::getStudentId).collect(Collectors.toList());
2:操作list排序
List<FanClassOrder> classOrderList = fanClassOrderMapper.selectFanClassOrderList(fanClassOrder);
//根据属性值筛选符合条件的数据
List<FanClassOrder> newList = classOrderList.parallelStream().filter(e->e.getClassId().equals("aa")).collect(Collectors.toList());
FanClassOrder fanClassOrders = classOrderList.parallelStream().filter(e->e.getClassId().equals("aa")).findFirst().orElse(null);
//排序 加reversed是倒序
classOrderList.sort(Comparator.comparing(FanClassOrder::getOrderTime).reversed());
3:对map集合排序
List<Map<String,Integer>> data = new ArrayList<>();
Map<String,Integer> map = new HashMap<>();
map.put("site",10);
data.add(map);
map = new HashMap<>();
map.put("site",6);
data.add(map);
map = new HashMap<>();
map.put("site",9);
data.add(map);
map = new HashMap<>();
map.put("site",8);
data.add(map);
map = new HashMap<>();
map.put("site",7);
data.add(map);
//正序
List<Map<String, Integer>> collect = data.stream().sorted((i, j) ->j.get("site") - i.get("site")).collect(Collectors.toList());
collect.stream().forEach(e-> System.out.println(e.get("site")));
System.out.println("-------------------");
//倒序
collect = data.stream().sorted((i, j) -> i.get("site") - j.get("site")).collect(Collectors.toList());
collect.stream().forEach(e-> System.out.println(e.get("site")));
4:String 转为 List<Map<String,Object>>
/**
* String 转为 List<Map<String,Object>>
* @param jsonFile
* @return
* @throws Exception
*/
public static List<Map<String,Object>> toMapListByString(String jsonFile) throws Exception{
List<Object> list = JSON.parseArray(jsonFile);
List<Map<String,Object>> listMap = new ArrayList<Map<String,Object>>();
for (Object object : list) {
Map<String,Object> ageMap = new HashMap<String,Object>();
Map <String,Object> ret = (Map<String, Object>) object;//取出list里面的值转为map
listMap.add(ret);
}
return listMap;
}