I have a multimap of Integer and List of String[]. Here I need to get the highest 10 values of the multimap based on the key.
I am trying to implement it in a way like, if the keys and values are as below,
Key Value
3 [0,0],[1,0],[0,1]
6 [0,1],[1,1],[0,0]
1 [1,0],[1,1],[0,1],[0,0]
2 [1,1],[0,0]
Now I have to get the highest 10 values based on the key.
As the first highest key is 6, it has to get all the values of 6 --> ([0,1],[1,1],[0,0])
Next get the remaining values of next highest key 3 which is --> ([0,0],[1,0],[0,1])
Next get the remaining values of next highest key 2 which is --> ([1,1],[0,0])
Next get the remaining values of next highest key 1 which is --> ([1,0],[1,1]).
As I need only 10 values, I have to pick only 2 values from the key 1 because (3 values[from key 6] + 3 values[from key 3] + 2 values [from key 2] + 2 values from key 1) which is a total of 10 values.
Here is my code:
Map<Integer, List<String[]>> outdoorElements = new HashMap<Integer, List<String[]>>();
putObjects(outdoorElements,EvaluationCount,schedules);
private static void putObjects (Map<Integer, List<String[]>> outdoorElements, Integer key, String[] value) {
List<String[]> myClassList = outdoorElements.get(key);
if(myClassList == null) {
myClassList = new ArrayList<String[]>();
outdoorElements.put(key, myClassList);
}
myClassList.add(value);
}
I am trying so hard how to get the values. Really appreciated if anyone could guide me through this.