If you wish to sort the strings and consider all numbers you can use a combination of regex and Java 8.
Consider a string like the following:
"SAMPLE:1-2-8-SAM#1"
This can be split up using a regular expression to a String[] like this
String s = "SAMPLE:1-2-8-SAM#1";
String[] arr = s.split("((?<=[:\\-#])|(?=[:\\-#]))");
System.out.println(Arrays.stream(arr).collect(Collectors.toList()));
The output would be:
[SAMPLE, :, 1, -, 2, -, 8, -, SAM, #, 1]
This means that we can treat index 0 like a String and index 2, 4, 6 and 10 as Integers.
So, in order to use that for sorting the following code can be used:
String[] strings = {
"SAMPLE:1-2-8-SAM#1",
"SAMPLE:1-1-8-SAM#1",
"SAMPLE:1-1-8-SAM#13",
"DEMO:1-1-4-SAM#13",
"DEMO:1-1-4-SAM#26",
"DEMO:1-1-4-SAM#8"
};
final List<String> sorted = Arrays.stream(strings)
.map(str -> str.split("((?<=[:\\-#])|(?=[:\\-#]))"))
.sorted(Comparator
.<String[], String>comparing((arr) -> arr[0]) // String compare
.thenComparing(arr -> Integer.valueOf(arr[2])) // Integer compare
.thenComparing(arr -> Integer.valueOf(arr[4])) // Integer compare
.thenComparing(arr -> Integer.valueOf(arr[6])) // Integer compare
.thenComparing(arr -> Integer.valueOf(arr[10]))) // Integer compare
.map(l -> Arrays.stream(l).collect(Collectors.joining())) // Map it back to a String
.collect(Collectors.toList()); // Collect it to a List for further processing
It is not super-readable but it works as per the OP:s question. If you also use some static imports the code is a bit easier to read.
However, my recommendation is to create a Comparator that does the sorting which will be more readable (and thereby easier to maintain in the long run).
#?