私はテーブルを持っています:
名前 | データ | アイテム
数 1 | 16 | 2
アイテム2 | 17 | 3
アイテム1 | 16 | 5
私はそれを次のように変換したいと思います:
{ item1: {16+16, 2+5}, item2: {17, 3}}
ただし、次の結果しか生成できません。
{ item1: 16+16, item2: 17}
次のコードを使用: Stats クラスには両方のフィールドが保存されますが、両方のフィールドをデータに追加する方法がわかりません
class Stats {
public Integer data, num;
public Stats(Integer td, Integer nf) {
data = td;
num = nf;
}
public Integer getdata(){
return data;
}
public Integer getnum(){
return num;
}
}
Map<String, Stats> map = new HashMap<>();
Stream<String> lines = Files.lines(Paths.get(table));
map = lines.map(x ->
.collect(Collectors.toMap(
z -> z[0],
z -> Integer.parseInt(z[1]),
(a, b) -> a+b));
上記のコードはMap<String, Int>
、どのように機能するかわからないため、のみ機能しMap<String, Stats>
ます。1 つのパイプラインのみを使用しながら、2 番目の列のアイテムをマップに取得する方法はありますか?