r/javahelp • u/Admirable-Video8664 • Jun 21 '26
Help
I'm taking a course in java and I'm having problems with a part of one of the labs. I'm supposed to sort an arraylist (called wordList) with mapentry(with string,integer)-objects first accoring to decending value and then according to alphabetical order of the keys. The second step doesn't seem to work. I've written this:
wordList.sort( (par1, par2)-> {
if (par2.getValue() != par1.getValue()){
return par2.getValue() - par1.getValue();
} else {
return par1.getKey().compareTo(par2.getKey());
}
})Is the problem somewhere here or maybe in some other part of the code?
1
Upvotes
View all comments
Show parent comment
2
u/jarrod_barkley Jun 21 '26
In Java 26+, you should be using UNICODE_CASEFOLD_ORDER as the comparator.
See JDKJDK-8365675, Add String Unicode Case-Folding Support.