Solved

Which of the Following Statements Correctly Provides a Comparator Function

Question 55

Multiple Choice

Which of the following statements correctly provides a comparator function using lambda expressions to sort an array of countries by population, assuming the existence of a getPopulation method?


A) Arrays.sort(countries, comparator(c -> c.getPopulation() ) ) ;
B) Arrays.sort(countries, compare(c1 -> c1.getPopulation() , c2 -> c2.getPopulation() ) ;
C) Arrays.sort(countries, (c1, c2) -> c1.getPopulation() - c2.getPopulation() ) ;
D) Arrays.sort(countries, c -> c.getPopulation() ) ;

Correct Answer:

verifed

Verified

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions