美文网首页
java十四(Lambda)箭头函数

java十四(Lambda)箭头函数

作者: Nic_ofh | 来源:发表于2017-10-01 23:19 被阅读0次

Demo(对象数组排序)

Student[] students = {new Student("张一", 20), new Student("张一", 18), new Student("张一", 30), new Student("张一", 17)};
Arrays.sort(students,(s1,s2)->s1.getAge()-s2.getAge()); // 按年龄从小到大排序
System.out.println(Arrays.tostring(students)) 

Student类

package Lambda闭包;

public class Student {
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }


}

详细介绍

http://www.importnew.com/16436.html

相关文章

网友评论

      本文标题:java十四(Lambda)箭头函数

      本文链接:https://www.haomeiwen.com/subject/jzfzextx.html