Is it possible to sort the current output of the code below in descending order without using comparators?
I've tried using one but I can't seem to make it work as it always gives an error.
I've tried looking at these two links as I know the answers might be in there:
Sort Map<String, Long> by value reversed , Sort a Map<Key, Value> by values
But since I'm quite new to java I don't really get what I need to do in order to get it working.
myRef.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot , String s) {
Map<String, Object> userInfo = (Map<String, Object>)dataSnapshot.getValue();
String username = (String) userInfo.get("username");
Map<String, Long> steps = (Map<String, Long>) userInfo.get("steps");
long existingSteps = 0;
for (Map.Entry<String, Long> step : steps.entrySet()) {
existingSteps += Long.valueOf(step.getValue());
}
arrayList.add(new String( username + " - " + "steps: " + existingSteps));
arrayAdapter = new ArrayAdapter<>(Leaderboard.this ,
android.R.layout.simple_list_item_1 , arrayList);
listView.setAdapter(arrayAdapter);
}
The current output of this code is:
John Doe I - Steps: 79
John Doe II - Steps: 111
John Doe III - Steps: 0
John Doe IV - Steps: 88
John Doe V - Steps: 12
John Doe VI - Steps: 0
preferred this code to run the following output:
John Doe II - Steps: 111
John Doe IV - Steps: 88
John Doe I - Steps: 79
John Doe V - Steps: 12
John Doe III - Steps: 0
John Doe VI - Steps: 0
Is it possible for someone to explain to me how I would need to use those said links to get it working for me so I could get the output as listed above ?