Ranking list of athletes in a ascended order [closed]

There are total scores of athletes. I want to sort the list by total scores and add the position (place) to position field. In case of equal scores, athletes must share the places, e.g. 3-4 and 3-4 instead of 3 and 4.

input date:
 - ABC 10, 
 - BBC 8, 
 - CBC 11,
 - ACD 8

expected output:
 pos,  name, score
- 1,   CBC,  11
- 2,   ABC,  10
- 3-4, BBC,  8
- 3-4, ACD,  8

My solution looks a bit complicated, is there any better way?

class Athlete {
   private String name;
   private Long totalScore;
   private String position;
}

List<Athlete> athletes = new ArrayList()<>;
...
        int i = 0;
        int rank = 0;
        long score = Integer.MIN_VALUE;
        Map<Integer, Integer> rankings = new HashMap<>();
        for (Athlete athlete : athletes) {
            ++i;
            if (score != athlete.getTotalScore()) {
                rank = i;
                rankings.put(rank, 1);
            } else {
                rankings.put(rank, rankings.get(rank) + 1);
            }
            athlete.setRank(rank + "");
            score = athlete.getTotalScore();
        }
        rankings.entrySet()
                .stream().filter(entry -> entry.getValue() > 1)
                .forEach(entry -> {
                    int pos = entry.getKey() - 1;
                    String cRank = entry.getKey() + "-" + (pos + entry.getValue());
                    IntStream.range(pos, pos + entry.getValue())
                            .forEach(p -> athletes.get(p).setRank(cRank));
                });

What

Answer

I’m not sure if you’re required to use streams, but the following is fairly simple:

List<Athlete> athletes = Arrays.asList(new Athlete("ABC", 10), new Athlete("BBC", 8),
                                       new Athlete("CBC", 11), new Athlete("ACD", 8));

Collections.sort(athletes, Comparator.comparing(Athlete::getScore).reversed());

for(int j = 0, i = 1; i <= athletes.size(); i++)
{
    if(i == athletes.size() || athletes.get(i).getScore() != athletes.get(j).getScore())
    {
        String pos = (j + 1) + ((j + 1 == i) ? "" : "-" + i);
        while (j < i) athletes.get(j++).setPosition(pos);
    }               
}


for(Athlete a : athletes) System.out.println(a);

Output:

1 : CBC : 11
2 : ABC : 10
3-4 : BBC : 8
3-4 : ACD : 8