我有两个数组在我的哈希映射中,我想根据timeStampArray
中的时间对存储在中的值进行排序。尝试使用TreeMap,但弄乱了它。 任何帮助都将非常可观。排序哈希映射
Map<List<Date>,List<Double>> unsortedMap = new HashMap<List<Date>,List<Double>>();
unsortedMap.put(timeStampArray, averageValueArray);
这是我想
Map<List<Date>,List<Double>> sortMap = new HashMap<List<Date>,List<Double>>();
sortMap.put(timeStampArray, averageValueArray);
for (Map.Entry entry : sortMap.entrySet()) {
System.out.println("Key = " + entry.getKey());
System.out.println(" Value = " +entry.getValue());
}
System.out.println("Unsort Map......");
printMap(sortMap);
System.out.println("Sorted Map......");
Map<List<Date>,List<Double>> treeMap = new TreeMap<List<Date>,List<Double>>(sortMap);
printMap(treeMap);
而且printMap为:
public static void printMap(Map<List<Date>,List<Double>> map) {
for (Map.Entry entry : map.entrySet()) {
System.out.println("Key : " + entry.getKey() + " Value : "
+ entry.getValue());}}
你能不能解析的数组和添加这些值,以树形图逐一?该shld排序它 – Lokesh
写一个像sortLists(列表list1,列表list2)它返回一个排序的hasmap的方法,因为你的列表类型已经可比较应该是相对容易的 –