美文网首页
java8 获取list对象第一个元素

java8 获取list对象第一个元素

作者: 有心丶人 | 来源:发表于2020-05-25 09:36 被阅读0次
    import lombok.*;
    
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;
    
    public class Demo {
    
    
        @Builder
        @Data
        @AllArgsConstructor
        @NoArgsConstructor
        @ToString
        static class LOL{
            //赛区
            private String area;
            //战队名称
            private String teamName;
            //战队选手
            List<String> player;
    
        }
        private static List<LOL> lols= new ArrayList<>();;
        static  {
             lols.add( new LOL( "LPL", "IG", Arrays.asList( "TheShy","JK","Rk","BaoLan","Ning") ));
             lols.add( new LOL( "LPL", "FPX", Arrays.asList( "Doinb","GimGoon","Tian","Lwx","Crisp") ));
             lols.add( new LOL( "LCK", "SKT", Arrays.asList( "faker","khan","child","teddy","mata") ));
        }
        public static void main(String[] args) {
            LOL lol = lols.stream().findFirst().orElse( null );
            System.out.println( lol );
    
        }
    }
    
    

    输出结果为:

    Demo.LOL(area=LPL, teamName=IG, player=[TheShy, JK, Rk, BaoLan, Ning])
    

    相关文章

      网友评论

          本文标题:java8 获取list对象第一个元素

          本文链接:https://www.haomeiwen.com/subject/rnueahtx.html