1、去重
List<Map<String,Object>> list1 = new ArrayList<>();
Map<String,Object> map = new HashMap();
Map<String,Object> map2 = new HashMap();
map.put("key","1");
map.put("value","a");
map2.put("key","2");
map2.put("value","a");
list1.add(map);
list1.add(map2);
list1.forEach(System.out::println);
List<Map<String, Object>> list2 = list1.stream().collect(
Collectors.collectingAndThen(
Collectors.toCollection(
() ->new TreeSet<>(Comparator.comparing(m->m.get("value").toString()))
),ArrayList::new
)
);
System.out.println("--------");
list2.forEach(System.out::println);
2、过滤
List<Map<String, Object>> shopDpjbxxMx = shopDpjbxx.stream().filter(e -> e.get("shop_satatus") !=null && e.get("shop_satatus").equals("开店")).collect(Collectors.toList());
3、按过滤并时间排序
List<Map<String, Object>> shopQylsxssjMx = shopQylsxssj.stream().filter(e -> e.get("company_sales_amount") !=null && Integer.parseInt(e.get("company_sales_amount").toString())>0).sorted((o1, o2) -> {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
Date dt1 = format.parse(o1.get("data_month").toString());
Date dt2 = format.parse(o2.get("data_month").toString());
// 默认降序, 升序的话 把 dt1 和 dt2 调换位置
return Long.compare(dt2.getTime(), dt1.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}).collect(Collectors.toList());