I am struggling to sort a stream of strings (or list, if you prefer) in natural order ignoring a prefix. The prefix begins always with let and could be followed by any numbers (example, let12 or let3021)
Sample input:
let3 art zero
let2 own kit dig
let1 art can
Sample desired output:
let1 art can
let3 art zero
let2 own kit dig
So a simple idea that I have tried is to do the following:
list.stream().sorted();
But the numbers get in the way, producing the following output:
let1 art can
let2 own kit dig
let3 art zero
How can achieve this result in a simple way? The ideal solution would be a Comparator, or anything that I can use in a stream flow.
Note: my attempt to use the Comparator failed due the fact that the prefix could be of any length.
Thank you for your time.