سؤال

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