【发布时间】:2017-07-25 07:48:23
【问题描述】:
我有一个数据集定义为List<List<Long>> dataSet,dataSet(List)中的元素有8个子元素,我想用数据集索引0元素组,最后建立一个地图地图>,怎么做?
旧代码是:
List<List<Long>> dataSet = .....;
Map<Long, Set<Long>> a = new HashMap<>();
for (List<Long> data : dataSet) {
Long userId = data.get(0);
Long targetId = date.get(7);
if (a.containsKey(userId)) {
a.get(userId).add(targetId);
} else {
Set<Long> ids = new HashSet<>();
ids.add(targetIds);
a.put(userId, ids);
}
}
【问题讨论】:
-
您的旧代码根本无法运行。您正在访问其范围之外的 userId 和 targetId 变量(for 循环)。您可能需要更正旧代码。这将有助于我们更好地理解需求。
-
对不起,这是我的错……
标签: list dictionary java-stream