0

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.

Brian Tompsett - 汤莱恩
  • 5,195
  • 62
  • 50
  • 120
CodeKingPlusPlus
  • 12,865
  • 46
  • 123
  • 204
  • This is the kind of thing you can teach yourself via Google and JavaDoc. Please do some research before posting so we can limit questions to ones that haven't already been answered better elsewhere. – Old Pro Apr 21 '12 at 04:38

1 Answers1

2
Map.Entry<String, Integer> sortedArray[] = new Map.Entry<String, Integer>[sortedTable.size()];
sortedArray = sortedTable.toArray(sortedArray);
Old Pro
  • 22,324
  • 4
  • 52
  • 96