如何在java

时间:2017-10-14 14:26:15

标签: java arraylist

如何过滤掉下面哪个List包含String" 1"在ArrayList

中List的索引0中
List<List<String>> a = new ArrayList<List<String>>();
a.add(Arrays.asList("1","2","3"));
a.add(Arrays.asList("4","5","6"));
a.add(Arrays.asList("2","1","8"));
a.add(Arrays.asList("1","1","8"));

和do filter之后的预期结果是:ListList中的列表索引0,3

1 个答案:

答案 0 :(得分:0)

检索索引:

int[] indexArray = IntStream.range(0, a.size()).filter(x -> a.get(x).get(0).equals("1")).toArray();

检索实际列表:

List<List<String>> resultSet = a.stream().filter(x -> x.get(0).equals("1")).collect(Collectors.toList());