This website requires JavaScript.

Java8实战:列表排序

代码地址:Sorting.java

老代码

 	// [Apple{color='green', weight=30}, Apple{color='green', weight=80}, Apple{color='green', weight=155}]
        inventory.sort(new Comparator<Apple>() {
            @Override
            public int compare(Apple a1, Apple a2){
                return a1.getWeight().compareTo(a2.getWeight()); 
        }});

Java8

inventory.sort(comparing(Apple::getWeight));
0条评论
avatar