一、Stream介绍  

现在有这样的需求:有个菜单list,菜单里面非常多的食物列表,只选取小于400卡路里的并且按照卡路里排序,然后只想知道对应的食物名字。

代码:

package com.cy.java8;

public class Dish {

    private final String name;
    private final boolean vegetarian;
    private final int calories;
    private final Type type;

    public Dish(String name, boolean vegetarian, int calories, Type type) {
        this.name = name;
        this.vegetarian = vegetarian;
        this.calories = calories;
        this.type = type;
    }


    public String getName() {
        return name;
    }

    public boolean isVegetarian() {
        return vegetarian;
    }

    public int getCalories() {
        return calories;
    }

    public Type getType() {
        return type;
    }

    public enum Type {MEAT, FISH, OTHER}


    @Override
    public String toString() {
        return "Dish{" +
                "name='" + name + '\'' +
                ", vegetarian=" + vegetarian +
                ", calories=" + calories +
                ", type=" + type +
                '}';
    }
}
View Code

相关文章:

  • 2022-12-23
  • 2021-07-20
  • 2021-05-15
  • 2021-11-20
  • 2021-05-17
  • 2021-12-08
  • 2022-02-03
  • 2021-12-14
猜你喜欢
  • 2021-06-07
  • 2022-12-23
  • 2021-09-04
  • 2022-12-23
  • 2021-06-08
  • 2021-12-06
  • 2022-12-23
相关资源
相似解决方案