Java8 新特性 Stream 练习实例

旧街凉风 提交于 2019-12-06 16:53:06

练习实例

配合Java8 新特性 Steam() API 使用

//没有写get set 构造方法
public class Sku {
    private Integer skuId;

    private String skuName;

    private Double skuPrice;

    private Integer totalNum;

    private Double totalPrice;

    private Enum skuCategory ;
}
public enum SkuCategoryEnum {
    CLOTHING(10, "服装类"),
    ELECTRONICS(20, "数码类"),
    SPORTS(30, "运动类"),
    BOOKS(40, "图书类");

    private Integer code;
    private String name;

    SkuCategoryEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }
}
//添加数据
private static List<Sku> cartSkuList = new ArrayList<Sku>() {
        {
            add(new Sku(100001, "无人机",
                    4999.00, 1,
                    4999.00, SkuCategoryEnum.ELECTRONICS));
            add(new Sku(100001, "VR一体机",
                    2299.00, 1,
                    2299.00, SkuCategoryEnum.ELECTRONICS));
            add(new Sku(100002, "纯色衬衫",
                    409.00, 3,
                    1227.00, SkuCategoryEnum.CLOTHING));
            add(new Sku(100003, "牛仔裤",
                    528.00, 1,
                    528.00, SkuCategoryEnum.CLOTHING));
            add(new Sku(100004, "跑步机",
                    2699.00, 1,
                    2699.00, SkuCategoryEnum.SPORTS));
            add(new Sku(100005, "Java编程思想",
                    79.80, 1,
                    79.80, SkuCategoryEnum.BOOKS));
            add(new Sku(100006, "Java核心技术",
                    149.00, 1,
                    149.00, SkuCategoryEnum.BOOKS));
            add(new Sku(100007, "算法",
                    78.20, 1,
                    78.20, SkuCategoryEnum.BOOKS));
            add(new Sku(100008, "TensorFlow进阶指南",
                    85.50, 1,
                    85.50, SkuCategoryEnum.BOOKS));
        }
    };
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!