Oh, those tricky Java 8 streams with lambdas. They are very powerful, yet the intricacies take a bit to wrap one\'s header around it all.
Let\'s say I have a U
What you want is Comparator#comparing:
userMap.values().stream()
.sorted(Comparator.comparing(User::getName, UserNameComparator.INSTANCE))
.collect(Collectors.toList());
For the second part of your question, you would just use
Comparator.comparing(
u->u.getProfile().getUsername(),
UserNameComparator.INSTANCE
)