zoukankan      html  css  js  c++  java
  • Stream API 和 注解

    Stream

     Stream特性

     Stream运行机制

     Stream常用API

     Stream的创建

    public class StreamDemo{
        static void gen1(){
            String[] args = {"a","b","c","d","e"};
            Stream<String> strs1 = Stream.of(strs);
            strs.forEach(System.out::println);
            for(String str : strs){
                System.out.println(str);
            }
        }
        
    
        static void gen2(){
            List<String> list = Arrays.asList("1","2","3","4","5");
            Stream<String> stream = list.stream();
            stream.forEach(System.out::println);
        }
    
        static void gen3(){
            Stream<Integer> generate = Stream->generate(()->{
                for(int i = 0; i < 1000; i++){
                    return i;
                }
            });
            generate.limit(10).forEach(System.out::println);
        }
    
        static void gen4(){
            Stream.iterate(1, x->x+1);
            iterate.limit(10).forEach(System.out.println);
        }
    
        static void gen5(){
            String str = "abc";
            Stream stream = str.chars();
            stream.forEach(System.out::println);
        }
    
        public static void main(String[] args){
            Arrays.asList(1,2,3,4,5).stream().filter((x)->x%2==0).forEach(System.out::println);    
            Arrays.asList(1,2,3,4,5,6,7,8,9).stream().filter(x->x%2==0).count();
            System.out.println(count);
    
            List<Integer> list = Arrays.asList(1,2,3,4,5,6);
            Optional <Integer> max = list.stream().max((a,b)->a-b);
        }    
    
    }

    Java自定义注解

    注解的作用

    元注解

    public class MetaAnnotation{
        public void test(){
    
        }
    }
    @MyAnnotation
    // target用来声明当前自定义注解适合用于什么地方,方法,变量,包
    @Target(ElementType.METHOD, ElementType.TYPE)
    // 注解适用于什么环境,源码级别,类级别,还是运行时
    @Retention(RetentionPolicy.CLASS)
    // 表示该注解是否显示在javadoc中
    @Decumented
    // 表示该注解是否能够继承
    @Inherited
    @interface MyAnnotation{
        
    }
    论读书
    睁开眼,书在面前
    闭上眼,书在心里
  • 相关阅读:
    进程线程模型
    操作系统运行机制
    操作系统概论
    排序
    win32消息机制
    win32框架
    map
    deque & list
    vector内部实现2
    蓝桥杯 文化之旅 图论 待复习
  • 原文地址:https://www.cnblogs.com/YC-L/p/14215243.html
Copyright © 2011-2022 走看看