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) );
rappel code b classe anonyme:
list.sort(new Comparator<Apple>() { @Override public int compare(Apple a1, Apple a2) { return a1.getWeight()-a2.getWeight(); }} );
code b lambda:
list.sort((Apple a1, Apple a2)-> a1.getWeight()-a2.getWeight());
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]
Top comments (0)