【发布时间】:2019-12-29 20:03:51
【问题描述】:
所以我想将 Person 放入一个数组列表中,但我需要使用流 我有 csv 文件,它给了我 infomartions 身份证;姓名;性别 以及使用那里的 id 将这些转换为 Person 对象的方法,
private Person readCSVLines(int id);
但我想创建一个方法给我一个数组列表,我知道有 807 id 并且不会再有一个了
我使用 toMap 尝试过这个,但它给了我一张地图,但我只想要一个 ArrayList:
public ArrayList<Person> getAllPerson() {
try (IntStream stream = IntStream.range(1, personmax)) { // personmax is 807 here
return stream.boxed().collect(
Collectors.toMap(
i -> i,
this::readCSVLines,
(i1, i2) -> {
throw new IllegalStateException();
},
ArrayList::new
)
);
}
}
【问题讨论】:
标签: java arraylist java-stream