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