Hey if anyone has an idea I would be really thankfull. I'm in a Java stream and i would like to sort my list that i'll be returning. I need to sort the list via TradPrefis ( MyObject::getTradPrefix ). But this would be way too easy. Because i want to sort following the number at the end of TradPrefix exampleTradPrefix_[NUMBER TO SORT]
Exemple : hello_1 test_2 ... still_there_22
Here is a piece of code so you can imagine easier.
public LinkedHashSet<WsQuestion> get(String quizId, String companyId) {
LinkedHashSet<QuizQuestionWithQuestion> toReturn = quizQuestionRepository.findAllQuizQuestionWithQuestionByQuizId(quizId);
return (toReturn.stream()
.map(this::createWsQuestion)
.sorted(comparing(WsQuestion::getTradPrefix.toString().length()))
.collect(Collectors.toCollection(LinkedHashSet::new)));
}
"11" < "2"
. You can only skip parsing to int when you can preclude differently sized strings and leading zeros or when you add special handling for these cases. – Smithsonite