compareTo() method on integer (Java 8, Comparable, Comparator, sorting, String) We can apply comparable & comparator both on integers, as like below: