我试图从列表中获取特定元素,但不是整个列表。例如,如果我
System.out.println(words.get(0))
我会得到
[16, Matthew, 13,954, Alexis, 8,181]
但是我怎么能在这一行得到一个特定的元素,比如Matthew这个名字,而不是整行。
[Matthew]
List<List<String>> words = topNames.stream()
.map(sentence -> sentence.split("\\s+"))
.map(Arrays::asList)
.collect(Collectors.toList());
System.out.println(words.get(0));
答案 0 :(得分:0)
添加map()
操作以映射到指定索引处的元素:
List<String> wordsAtTheOneIndex = topNames.stream()
.map(sentence -> sentence.split("\\s+"))
.map(Arrays::asList)
.map(l -> l.get(1))
.collect(Collectors.toList());