现在有如下需求
HashMap<String,Integer> hashMap1=new HashMap<>();
List<HashMap<String,Integer>> list1=new ArrayList<>();
for (int i = 0; i < 10; i++) {
hashMap1.put("A",i);
hashMap1.put("B",new Random().nextInt(100));
hashMap1.put("C",new Random().nextInt(100));
list1.add(hashMap1);
}
HashMap<String,Integer> hashMap2=new HashMap<>();
List<HashMap<String,Integer>> list2=new ArrayList<>();
for (int i = 0; i < 5; i++) {
hashMap2.put("B",new Random().nextInt(100));
hashMap2.put("C",new Random().nextInt(100));
list2.add(hashMap2);
}
这样一来,list1中的元素顺序,已经按照hashmap的A字段排好顺序,但B和C字段是乱序,同理,hashmap2的B和C字段,也是乱序
那么如何在不打破A字段的排序前提下,将list1和list2合并,并将排序以B字段为主,C字段为辅进行排序?
(可以把A字段看成某个业务的工单序号,B和C字段是日期和时间,合并后的list出现以下效果:
1 20200101 93000(时间和日期可以简单地以数字处理,有序号的为list1中的数据,没有的为list2中的数据)
2 20200101 83001
20200101 83002
20200101 84015
3 20200102 153030
20200102 153100
20200102 153200
)