해시 맵에 두 개의 배열이 있는데 timeStampArray
의 시간에 따라 averageValueArray
에 저장된 값을 정렬하려고합니다. TreeMap을 사용해 보았지만 엉망으로 만들었습니다. 도움이 될 것입니다. HashMaps 정렬
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());}}
당신이 배열을 분석하고 하나 하나 트리 맵에 그 값을 추가 할 수 있습니까? that shld sort – Lokesh
정렬 된 hasmap을 반환하는 sortLists (List list1, List list2)와 같은 메소드를 작성하고 목록 유형이 이미 비교 가능하기 때문에 비교적 쉽다. –