【发布时间】:2018-02-07 11:02:14
【问题描述】:
我想基于 customerProduct 使用 java
做下面的数据 groupBy[{customerID=123,customerName=John,customerProduct=mobile},
{customerID=456,customerName=roach,customerProduct=laptop},
{customerID=678,customerName=david,customerProduct=mobile},
{customerID=678,customerName=abd,customerProduct=charger}]
我们如何在 java 8 中做到这一点
期待如下
{
mobile= [
{customerID=123,customerName=John,customerProduct=mobile},
{customerID=678,customerName=david,customerProduct=mobile},
],
laptop= [{customerID=456,customerName=roach,customerProduct=laptop}],
charger= [{customerID=678,customerName=abd,customerProduct=charger}]
}
【问题讨论】:
-
您对这个样本数据的预期结果是什么?
-
我们没有您的信息。从我们的角度来看,我们不知道你想做什么。请添加一些上下文、一些示例等...此外,您应该将您的问题改写为“在 Java 中对数组进行排序”,因为对列表进行排序更容易。
-
输出应该是这样的 { mobile= [ {customerID=123,customerName=John,customerProduct=mobile}, {customerID=678,customerName=david,customerProduct=mobile}, ], laptop= [ {customerID=456,customerName=roach,customerProduct=laptop}], 充电器= [{customerID=678,customerName=abd,customerProduct=charger}] }
标签: java arrays spring web-services collections