Check out example codes for "Compare integers java sort". It will help you in understanding the concepts better.

Code Example 1

public class AgeComparatorDesc implements Comparator<Student> {

  @Override
  public int compare(Student o1, Student o2) {
    if (o1.age > o2.age) {
        return -1;
    } else if (o1.age < o2.age) {
        return 1;
    }    
     return 0;
  }

}

Learn ReactJs, React Native from akashmittal.com