`
wuxiaozeng2440
  • 浏览: 25776 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

分组方法

    博客分类:
  • code
 
阅读更多

public static Map<String, List<Map<String, Object>>> list2Map(String key, List<Map<String, Object>> data) {

 

if (data == null) return null;

Map<String, List<Map<String, Object>>> result = new HashMap<String, List<Map<String, Object>>>();

for (Map<String, Object> map : data) {

if (map.get(key) == null) continue;

List<Map<String, Object>> tempList = result.get(map.get(key).toString());

// 如果取不到数据,那么直接new一个空的ArrayList

if (tempList == null) {

tempList = new ArrayList<>();

tempList.add(map);

result.put(map.get(key).toString(), tempList);

} else {

// 某个sku之前已经存放过了,则直接追加数据到原来的List里

tempList.add(map);

}

}

return result;

}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics