Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

lou
lou

Posted on • Edited on

     

Lambda exemple Comparator bDarija

Had l'exemple fih implementation dial comparator bLambda

hna baghin nretbo list bcomparator walakin had lmerra b lambda

la liste qbl:

 List<Apple> list= Arrays.asList(                new Apple(140,Color.RED),                new Apple(190,Color.RED),                new Apple(150,Color.GREEN),                new Apple(100,Color.GREEN),                new Apple(170,Color.RED),                new Apple(110,Color.GREEN)                );
Enter fullscreen modeExit fullscreen mode

rappel code b classe anonyme:

list.sort(new Comparator<Apple>() {@Overridepublic int compare(Apple a1, Apple a2) {    return a1.getWeight()-a2.getWeight();}});
Enter fullscreen modeExit fullscreen mode

code b lambda:

list.sort((Apple a1, Apple a2)-> a1.getWeight()-a2.getWeight());
Enter fullscreen modeExit fullscreen mode

Resultat la liste mn b3d:

Apple [weight=100, color=GREEN]Apple [weight=110, color=GREEN]Apple [weight=140, color=RED]Apple [weight=150, color=GREEN]Apple [weight=170, color=RED]Apple [weight=190, color=RED]
Enter fullscreen modeExit fullscreen mode

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Hi! I made this blog because I find that explaining things is the key to retaining information ✨
  • Education
    EMSI
  • Joined

More fromlou

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp