public int add(int x, int y) {
return x + y;
}
(int x, int y) -> x + y;
(x, y) -> x + y; //返回两数之和
(x, y) -> { return x + y; } //显式指明返回值
() -> { System.out.println("Hello Lambda!"); }
c -> { return c.size(); }
public static void main(String[] args) {
Arrays.asList( "a", "b", "d" ).forEach( e -> {
System.out.print( e +"\n");
} );
System.out.print( "\n--------------------------" );
Arrays.asList( "a", "b", "d" ).sort( ( e1, e2 ) -> e1.compareTo( e2 ) );
/**
* 可见λ表达式有三部分组成:参数列表,箭头(->),以及一个表达式或语句块。
* 下面这个例子里的λ表达式没有参数,也没有返回值(相当于一个方法接受0个参数,返回void,其实就是Runnable里run方法的一个实现):
* () -> { System.out.println("Hello Lambda!"); }
*/
Thread t2=new Thread(()->{
System.out.println("This is from an anonymous method (lambda exp).\n");
});
t2.start();
/**
* 迭代LIST
*/
List<String> listStr=new ArrayList<>();
listStr.add("sss");
listStr.add("1111");
listStr.forEach(e->{
if(e.equals("sss")){
System.out.print(e);
}
});
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有