JAVA8--前言

1.语言生态系统的思想,以及语言 面临的”要么改变,要么衰亡”的压力.虽然java现在非常有活力,但曾今有很多有活力已经衰亡的语言如COBOL
2.java8中新增的核心内容提供了令人激动的新概念和功能,方便我们编写既有效又简洁的程序
3.现有的java编程实践并不能很好地利用多核处理器
4.函数是一等值,记得方法如何作为函数式值来传递,还有lambda是怎么样写的
5.java8中stream的概念使得Collections的许多方面得以推广,让代码更为易读,并允许并行处理流元素
6.可以在接口中直接使用默认方法,在实现类没有实现方法时提供方法内容
7.新的null的处理方式和模式匹配等

 public class Apple{
        private String color;
        private int weight;

        public Apple(String color, int weight) {
            this.color = color;
            this.weight = weight;
        }

        public String getColor() {
            return color;
        }

        public void setColor(String color) {
            this.color = color;
        }

        public int getWeight() {
            return weight;
        }

        public void setWeight(int weight) {
            this.weight = weight;
        }
    }

    public void cc(){
        List<Apple> appleList=new ArrayList<>();
        List<Apple> appleList1=new ArrayList<>();
        appleList.add(new Apple("yellow",150));
        appleList.add(new Apple("green",100));
        appleList.add(new Apple("green",150));
        appleList1.add(new Apple("red",300));
        appleList1.add(new Apple("red",300));
        Map<Integer,List<Apple>>maps=  appleList.stream().filter((Apple a)->a.getWeight()>90).collect(groupingBy(Apple::getWeight));

        Map<Integer,List<Apple>>maps2=new HashMap<>();

        maps.forEach((a,k)->{
            if (k.stream().filter((Apple l)->l.getWeight()>100).collect(Collectors.toList()).size()!=0){
                maps2.put(a,k.stream().filter((Apple l)->l.getWeight()>100).collect(Collectors.toList()));
            }

        });//(a,k)->k.get(a).getColor()
        maps.forEach((a,k)->{
            if (a>100){
                maps2.put(a,k);
            }
        });



    }

猜你喜欢

转载自blog.csdn.net/ljm15832631631/article/details/81083787