zoukankan      html  css  js  c++  java
  • java8 常用函数式接口

      

      

    public static void main(String[] args) {
            // TODO Auto-generated method stub
            //函数式接口
            
            Function<Integer, String[]> f=x->new String[x];
            String[] strs=f.apply(10);
            System.out.println(strs.length);    //10
            
            Runnable r=()->System.out.println("Runnable接口");
            r.run();      //Runnable接口
            
            Supplier<Integer> s=()->{
                Integer i=100;
                //.....
                return i;
            };
            System.out.println(s.get());    //100
            
            
            Consumer<Double> c=d->{
                System.out.println(d);
            };
            c.accept(100.001);  //100.001
            
            
            BiConsumer<Integer,String[]> b=(a,st)->{
                System.out.println(a);
                for(int i=0;i<st.length;i++){
                    st[i]=st[i].toUpperCase();
                    System.out.print(st[i]+"    ");
                }
                System.out.println();
            };
            String[] sts=new String[]{"hello","world"};
            b.accept(99, sts);   //HELLO    WORLD   
            
            BiFunction<Integer, Double, String> bi=(one,second)->{
                String sone=""+one+second;
                return sone;
            };
            System.out.println(bi.apply(123, 456.789));   //123456.789
            
        }
    View Code
    
    

     

  • 相关阅读:
    kill process
    USB development guide
    MMC device
    memtester
    printf()格式化输出详解
    C语言动态内存分配
    归并排序C语言
    c 文件操作
    数据包分析
    C语言文件操作函数大全
  • 原文地址:https://www.cnblogs.com/xiu68/p/7412215.html
Copyright © 2011-2022 走看看