Question

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.

Was it helpful?

Solution

Map.Entry<String, Integer> sortedArray[] = new Map.Entry<String, Integer>[sortedTable.size()];
sortedArray = sortedTable.toArray(sortedArray);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top