How to get List of List instead of List of Array from a stream?

时间:2017-10-12 09:45:04

标签: java arrays list java-stream

I want to got a List of List instead of List of Array in the below code:

List<String[]> list = org.simpleflatmapper.csv.CsvParser.reader(in).stream().collect(Collectors.toList());

How can we got List<List<String>> list = ... ?

2 个答案:

答案 0 :(得分:2)

you need to map String[] to List

List<List<String>> list = org.simpleflatmapper.csv.CsvParser.reader(in).stream()
.map(Arrays::asList)
.collect(Collectors.toList());

答案 1 :(得分:1)

org.simpleflatmapper.csv.CsvParser.reader(in).stream()
          .map(Arrays::asList)
          .collect(Collectors.toList());