zoukankan      html  css  js  c++  java
  • stream流的统计demo

    Stream流简单demo,直接获取list集合的相关数据

    /**
     * 
     */
    package lambda;
    
    import java.util.ArrayList;
    import java.util.DoubleSummaryStatistics;
    import java.util.List;
    
    /**
     * @author Administrator
     *
     */
    public class StreamDemo {
        public static void main(String[] args) {
            List<Order> list = new ArrayList<>();
            list.add(new Order("西瓜", 2.8, 100));
            list.add(new Order("苹果", 8.8, 100));
            list.add(new Order("芒果", 12.8, 100));
            list.add(new Order("葡萄", 9.8, 100));
    
            // Stream<Order> stream = list.stream();
            DoubleSummaryStatistics statistics
                = list.stream().mapToDouble(((obj) -> obj.getAmount() * obj.getPrice())).summaryStatistics();
            System.out.println("订单均值:" + statistics.getAverage());
            System.out.println("订单最大值:" + statistics.getMax());
            System.out.println("订单最小值:" + statistics.getMin());
            System.out.println("订单总数:" + statistics.getCount());
            System.out.println("订单总额:" + statistics.getSum());
        }
    }
    
    /**
     * 虚拟订单
     */
    class Order {
        // 订单名称
        private String title;
        // 订单价格
        private Double price;
        // 订单数量
        private int amount;
    
        /**
         * @return the title
         */
        public String getTitle() {
            return title;
        }
    
        /**
         * @param title the title to set
         */
        public void setTitle(String title) {
            this.title = title;
        }
    
        /**
         * @return the price
         */
        public Double getPrice() {
            return price;
        }
    
        /**
         * @param price the price to set
         */
        public void setPrice(Double price) {
            this.price = price;
        }
    
        /**
         * @return the amount
         */
        public int getAmount() {
            return amount;
        }
    
        /**
         * @param amount the amount to set
         */
        public void setAmount(int amount) {
            this.amount = amount;
        }
    
        public Order(String title, Double price, int amount) {
            this.title = title;
            this.price = price;
            this.amount = amount;
        }
    }
  • 相关阅读:
    移动设备横竖屏判断 CSS 、JS
    Jquery监听value的变化
    设置了line-block的div会出现间隙
    移动端点击可点击元素时,出现蓝色默认背景色
    网页顶部进度条-NProcess.js
    ios UITableView
    ios UIScrollView
    ios Xcode 快捷方式
    ios常用方法、基础语法总结
    Mac eclipse Tomcat安装
  • 原文地址:https://www.cnblogs.com/dayu007/p/10598950.html
Copyright © 2011-2022 走看看