码迷,mamicode.com
首页 > 编程语言 > 详细

java8 新特性(一)

时间:2019-01-16 23:56:42      阅读:350      评论:0      收藏:0      [点我收藏+]

标签:add   java   --   static   list   color   col   输出   静态   

直接上码:

public class demo {

private static String prints(String str){
str+="---helloworld";
System.out.println(str);
return str;
}

public static void main(String[] args) {

List<String> list = new ArrayList<String>();
list.add("a");
list.add("b");
list.add("c");
System.out.println(list);
System.out.println("=1.=====================");

for(int a=0;a<list.size();a++){
System.out.println(list.get(a));
}
System.out.println("=2.=====================");

for(String a: list){
System.out.println(a);
}
System.out.println("=3.====================使用java8===");

list.forEach((a)->System.out.println(a));

System.out.println("=4.====================");

list.forEach(System.out::println);

System.out.println("=5.====================");
list.forEach(demo::prints);

 

 

输出结果:

[a, b, c]
=1.=====================
a
b
c
=2.=====================
a
b
c
=3.====================使用java8===
a
b
c
=4.====================
a
b
c
=5.====================
a---helloworld
b---helloworld
c---helloworld

 

需要注意的是:“::”对应的方法是静态的,当然也可以是构造方法,另外再写出。

 

java8 新特性(一)

标签:add   java   --   static   list   color   col   输出   静态   

原文地址:https://www.cnblogs.com/xby-123/p/10280054.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!