C.S.F.P

public static void main(String[] args) {
Runnable runnable = new Runnable() {
@Override
public void run() {
System.out.println(“我来来”);
}
};

    Runnable runnable1 = () -> {
        System.out.println("我也来来");
    };
    runnable.run();
    runnable1.run();

    List<Student> students = Lists.newArrayList();
    Student student = new Student();
    student.setAge(11);
    students.add(student);

    Student student1 = new Student();
    student1.setAge(22);
    students.add(student1);


    Predicate<Student> predicate = (e)->e.getAge()>21;
    students.stream().filter(predicate).forEach(System.out::println);
    System.out.println("------------------");

    // 相当于诸葛亮给了赵云一道锦囊,在必要的时候打开
    execConsumer(student,(e)->{
        System.out.println(e.getAge());
    });
    System.out.println("------------------");


    // 相当于建筑师把图纸画好,给施工队执行,并返回质检报告
    Random r = new Random();
    List<Integer> integers = execSupplier(() -> r.nextInt(30), 10);
    integers.stream().forEach(System.out::println);
    System.out.println("------------------");

    // 相当于大白兔厂,Function.apply 是厂的流水线 牛奶+白沙糖是入参 产出大白兔是出参 注:Function第一个参数是入参,第二个参数是出参类型
    String resultStr = execFunction(" 123 ",e->e.trim());
    System.out.println(resultStr);
    String s = execFunction("123", e -> e.substring(0, 1));
    System.out.println(s);
    System.out.println("------------------");

    // 相当于海瑞拿着大明律法 对付官场之人,对就是对,错就是错,管你老几,皇上犯错也的骂
    Boolean aBoolean = execPredicate("", e -> e.isEmpty());
    System.out.println(aBoolean);

}

private static Boolean execPredicate(String s, Predicate<String> o) {
    return o.test(s);
}

private static String execFunction(String s, Function<String,String> function) {
    String apply = function.apply(s);
    return apply;
}

public static void execConsumer(Student m, Consumer<Student> consumer){
    consumer.accept(m);
}

public static List<Integer> execSupplier(Supplier<Integer> supplier,Integer n){
    ArrayList<Integer> ns = Lists.newArrayList();
    for (int i = 0; i < n; i++) {
        ns.add(supplier.get());
    }
    return ns;
}


static class Student{
    private Integer age;

    public Integer getAge() {
        return age;
    }

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

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                '}';
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值