Java Lambda 筛选 filter
生活随笔
收集整理的這篇文章主要介紹了
Java Lambda 筛选 filter
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Java Lambda 篩選 filter
public class Menu {/*** 菜品名稱*/private String name;/*** 菜品單價*/private Double price;/*** 菜品斤數*/private Double kilo;/*** 菜品類型:蔬菜、水果、肉類*/private String type;public Menu() {}public Menu(String name, Double price, Double kilo, String type) {super();this.name = name;this.price = price;this.kilo = kilo;this.type = type;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Double getPrice() {return price;}public void setPrice(Double price) {this.price = price;}public Double getKilo() {return kilo;}public void setKilo(Double kilo) {this.kilo = kilo;}public String getType() {return type;}public void setType(String type) {this.type = type;}} Menu pork = new Menu("豬肉", 9.9, 10.0, "肉類"); Menu beef = new Menu("牛肉", 38.8, 5.0, "肉類"); Menu chicken = new Menu("雞肉", 6.5, 30.0, "肉類"); Menu tomato = new Menu("土豆", 3.5, 30.0, "蔬菜"); Menu potato = new Menu("西紅柿", 7.5, 20.0, "蔬菜"); Menu apple = new Menu("蘋果", 3.5, 20.0, "水果"); Menu orange = new Menu("橙子", 4.0, 20.0, "水果"); List<Menu> menuList = Arrays.asList(pork, beef, chicken, tomato, potato, apple, orange); //篩選 List<Menu> fruitsMenuList = menuList.stream().filter(menu -> menu.getType().equals("水果")).collect(Collectors.toList()); fruitsMenuList.forEach(fruitMenu -> {System.out.println(fruitMenu.getName()); }); //蘋果 //橙子總結
以上是生活随笔為你收集整理的Java Lambda 筛选 filter的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SDCMS1.31调用指定栏目信息的代码
- 下一篇: 萝卜家园 Win XP 极速安装版 3.