Java List实现group by

一般情况下我们可能很熟悉在数据库中使用group by来分组一些数据,但是如果数据来源不是数据库的话可能就需要通过在代码中实现group by了 例子:比如有一组书Book的集合,我们要按照书的类型(type)分组 12345678910111213package org.xuan;import lombok.AllArgsConstructor;import lombok.Data;@Data@AllArgsConstructorpublic class Book { private String name; private String type; private double price;} 增加几本书到list 123456789List <Book> bookList =Arrays.asList( new Book("java programming","java",123.1D), new Book("java in concurrency","java",123.2D), new Book("c++ primary","c++",123.3D), new Book("groovy in action","groovy",123.4D), new Book("effective java","java",123.5D), new Book("jvm in practice","java",123.6D), new Book("scala in action","scala",123.7D) );

java

本站由 Hank Zhao 使用 Stellar 主题创建。
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。
本站总访问量