Return to site

JAVA CERTIFICATION QUESTION: Sorting lists by multiple criteria

ยท java

Given:

and this code fragment:

๐–๐ก๐ข๐œ๐ก ๐œ๐จ๐๐ž ๐ฌ๐จ๐ซ๐ญ๐ฌ ๐š๐ง๐ข๐ฆ๐š๐ฅ๐ฌ ๐ข๐ง ๐ญ๐ก๐ž ๐จ๐ซ๐๐ž๐ซ: ๐–๐จ๐ซ๐ฆ, ๐…๐ฅ๐ฒ, ๐ƒ๐ซ๐š๐ ๐จ๐ง๐Ÿ๐ฅ๐ฒ, ๐’๐ฉ๐ข๐๐ž๐ซ?

๐€.ย 

list.stream().sorted(Comparator.comparing(a -> a.getNumOfLegs()).thenComparing(a -> a.getNumOfWings())).collect(Collectors.toList());

๐.ย 

list.stream().sorted(Comparator.comparing(a -> a.getNumOfWings()).thenComparing(a -> a.getNumOfLegs())).collect(Collectors.toList());

๐‚.ย 

list.stream().sorted(Comparator.comparing(a -> a.getNumOfLegs())).sorted(Comparator.comparing(a -> a.getNumOfWings())).collect(Collectors.toList());

๐ƒ.

list.sort((la, ra) -> {

ห‘if (la.getNumOfLegs() == ra.getNumOfLegs()) {

ห‘ห‘return Integer.compare(la.getNumOfWings(),

ห‘ห‘ห‘ ra.getNumOfWings());

ห‘} else {

ห‘ห‘return Integer.compare(la.getNumOfLegs(),

ห‘ห‘ห‘ra.getNumOfLegs());|

ห‘}

});

๐„. None of these answers

ยทฦŽ uoแด‰ส‡do sแด‰ ษนวสsuษ ส‡ษ”วษนษนoษ” วษฅ๊“•

All Posts
ร—

Almost doneโ€ฆ

We just sent you an email.ย Please click the link in the email to confirm your subscription!

OK