zoukankan      html  css  js  c++  java
  • java8 新特性(一)

    直接上码:

    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

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

  • 相关阅读:
    【二分】Pair of Topics
    【Windows】制作登录界面
    【Windows】制作文本框
    【windows】制作幸运“Tiger”机
    【python】函数
    SPOJ 3267 DQUERY
    CF 570D Tree Requests
    UVa 11809 Floating-Point Numbers
    Luogu P5098 Cave Cows 3
    GHOJ 428 未出现的子串
  • 原文地址:https://www.cnblogs.com/xby-123/p/10280054.html
Copyright © 2011-2022 走看看