I have a String list of numbers (they can be an int list, just need to turn it into an array list to return), this numbers can be from a range, for example from 1 to 25.
I tried sorting them using Collections.sort(numbersList);
but it sorts them in a weird way. For example this is the current sorting:
1
10
11
..
2
20
21
..
What I really want is for it to be sorted in a numerical order, for example:
1
2
3
..
10
11
..
Tried to sort them as an int[]
with Arrays.sort(numbers);
but it gives the same result.
Here is the code that I use to generate the numbers and turn them into an array list.
int[] range = IntStream.rangeClosed(1, 30).toArray();
Arrays.sort(range);
List<String> rangeList = new ArrayList<>();
for (int number : range) {
rangeList.add(String.valueOf(number));
}