有一种简洁的方法可以在Java 8中使用索引来迭代流吗?
String[] names = {"Sam","Pamela", "Dave", "Pascal", "Erik"};List<String> nameList;Stream<Integer> indices = intRange(1, names.length).boxed(); nameList = zip(indices, stream(names), SimpleEntry::new) .filter(e -> e.getValue().length() <= e.getKey()) .map(Entry::getValue) .collect(toList());
string[] names = { "Sam", "Pamela", "Dave", "Pascal", "Erik" };var nameList = names.Where((c, index) => c.Length <= index + 1).ToList();
慕码人8056858
相关分类