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

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

  • 相关阅读:
    select选中值传递到后台action中
    select into from 与insert into select from区别
    存储过程
    layer
    下拉框两级联动
    无限纠结——Zedboard上跑ubuntu详解
    静态时序分析SAT
    设计模式-(构型模式)
    内存断点调试的原理
    C语言中使用静态函数的好处
  • 原文地址:https://www.cnblogs.com/xby-123/p/10280054.html
Copyright © 2011-2022 走看看