java如何对一堆键值对数据分组

2025-04-01 19:46:38
推荐回答(3个)
回答1:

要实现什么功能`按什么要求分组``有什么样数据?

回答2:

public static Map> orgnaizeData(ResultSet rs) {
Map> result = null;
try {
if (rs.getRow() > 0) {
result = new HashMap>();
while (rs.next()) {
Long key = rs.getLong(1);
Long value = rs.getLong(2);
if (result.containsKey(key)) {
result.get(key).add(value);
} else {
List valueList = new ArrayList();
valueList.add(value);
result.put(key, valueList);
}
}
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}

回答3:

比如说,....