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 cartSkuList = new ArrayList() {
        {
            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));
        }
    };

你可能感兴趣的:(Java8 新特性 Stream 练习实例)