阅读背景:

Stream_weixin_30509393的博客

来源:互联网 

返回低热量的菜肴名称,并按照卡路里排序:

package com.ant.jdk8.chap04;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

public class StreamDemo {
    public static void main(String[] args) {
        List<Dish> menu = Arrays.asList(
                new Dish("pork", false, 800, Type.MEAT),
                new Dish("beef", false, 700, Type.MEAT),
                new Dish("chicken", false, 400, Type.MEAT),
                new Dish("french fries", true, 530, Type.OTHER),
                new Dish("rice", true, 350, Type.OTHER),
                new Dish("season fruit", true, 120, Type.OTHER),
                new Dish("pizza", true, 550, Type.OTHER),
                new Dish("prawns", false, 300, Type.FISH),
                new Dish("salmon", false, 450, Type.FISH) );
        menu.stream()
                .filter(d->d.getCalories()<400)
                .sorted(Comparator.comparing(Dish::getCalories))
                .map(Dish::getName)
                .forEach(name-> System.out.println(name));
    }
}
package com.an



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: