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:
Verified
Q77: An algorithm that tests whether the first
Q78: A portion of your program includes the
Q79: BBBBBBBBBBBBBBBBBBBBBBBBBBThe code segment below displays a table
Q80: The method findLargest examines the elements of
Q81: Complete the code shown to define the
Q83: What must be true about the return
Q84: Suppose a developer gets class XYZ files
Q85: Which of the following classes implement the
Q86: The _ class contains a sort method
Q87: Suppose the call obj1.compareTo(obj2) returns 0.What can
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents