Some time ago I have this doubt which says, how can I compare several String respecting the numerical data that may contain as in the re-naming of files of any folder. I was investigating, and why when comparing the Strings with this type of data is different from what one expects, it is because they are ordered in a lexicographical way (Character by character) but still I can not find a way to solve it.
Also I would like to say that I can not just put all the characters that are not numbers and sort them, because in the Strings that I am using they can have numbers in between.
This is an example of my problem
String[] nombres = {"hola 1", "hola 5", "hola 15", "hola 2};
//Ordena el array
Arrays.sort(nombres);
//Array ya ordenado
for (String i : nombres) {
System.out.print(i + ", ");
}
The result I get is:
hello 1, hello 15, hello 2, hello 5
The result I want is:
hello 1, hello 2, hello 5, hello 15
I would like to know if there is a method to solve my problem.