How to reverse a number in Java?

To reverse a number in Java, first split the number into a list of digits, then reverse the list, finally join it back and parse to a number.

Here's how you do it:

int number = 12345;

java.util.List<String> list = java.util.Arrays.asList(String.valueOf(number).split(""));
java.util.Collections.reverse(list);

int reversedNumber = Integer.parseInt(String.join("", list));

System.out.println(reversedNumber); // 54321