Java8 新特性 Stream 练习实例

练习实例

配合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(100000, "无人机",
                    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));
        }
    };


关注公众号,随时获取最新资讯

细节决定成败!
个人愚见,如有不对,恳请斧正!

posted @ 2019-12-06 16:22  一点浩然气~  阅读(1385)  评论(0编辑  收藏  举报