Sorting an Integer list as if it were a String list in Java

Viewed 125

I have a simple array of integers and I want to sort them but by String rules

Example: {1, 7, 43, 15, 2, 12} -> {1, 12, 15, 2, 43, 7}

I looked around and found Integer.toString(int) and String.valueOf(int) but that requires to make a new String array and convert them individually and sort it and convert it back to Integer and reassign it. Also, a Comparator I presume wouldn't be much different.

So are there more ways to do this?

5 Answers
Related