문제

I have these two data structures:

public TreeMap<String, Integer> tableFrequency;                  

public SortedSet<Map.Entry<String, Integer>> sortedTable;

sortedTable holds the same information as tableFrequency but it is sorted descendingly by the Integer value.

How can I convert sortedTable into an Array consisting of pairs of strings and integers, such that the Array is indexed to keep the same order as the sortedTable? For example to be more clear my array at index 0 would contain the largest value in sortedTable and my array at index[sortedTable.size() - 1] would contain the smallest value in sortedTable.

도움이 되었습니까?

해결책

Map.Entry<String, Integer> sortedArray[] = new Map.Entry<String, Integer>[sortedTable.size()];
sortedArray = sortedTable.toArray(sortedArray);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top