I need to sort an array of strings like the following, by a substring of characters:
[0] = "gtrd3455";
[1] = "wsft885";
[2] = "ltzy96545";
[3] = "scry5558";
[4] = "lopa475";
I need to sort by the following “3455, 885, 96545, 5558, 475”
I need to substring off the first 4 characters of the array, sort it and display back in an array like the output below.
The output should be an array like:
[0] = "ltzy96545";
[1] = "scry5558";
[2] = "gtrd3455";
[3] = "wsft885";
[4] = "lopa475";
Example of how I can do this in Java?
You can use a
Comparator, and useArray#sortmethod with it, to sort it according to your need: –OUTPUT: –