I have following code:
users.stream()
.sorted((u1, u2) -> u2.getScore().compareTo(u1.getScore()))
.limit(count)
.collect(Collectors.toMap((User::getName), (User::getScore)));
Content of result is right but when I want to foreach it - it output in unpredictable result. I think it is because under the hood HashMap is used.
Is there way to collect to mp with predictable result?