June 2018
Beginner
722 pages
18h 47m
English
The method int compare(T a, T b, Comparator<T> c) of the class Objects uses the provided comparator's method compare(T o1, T o2) for comparing the two objects. We have described already the behavior of the compare(T o1, T o2) method while talking about sorting collections, so the following results should be expected:
int diff = Objects.compare("a", "c", Comparator.naturalOrder());System.out.println(diff); //prints: -2diff = Objects.compare("a", "c", Comparator.reverseOrder());System.out.println(diff); //prints: 2diff = Objects.compare(3, 5, Comparator.naturalOrder());System.out.println(diff); //prints: -1diff = Objects.compare(3, 5, Comparator.reverseOrder());System.out.println(diff); //prints: 1
As we have mentioned already, the ...
Read now
Unlock full access