I am relatively new to Java, and the whole sort by using comparators is a bit confusing to me.
Is it possible to sort the current output of the code below in descending order without using comparators?
Or is there an easier way for me to understand how to sort said values.
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
Is it possible to get 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