Just for completeness here's the solution involving my StreamEx library:
String[] names = {"Sam","Pamela", "Dave", "Pascal", "Erik"};
EntryStream.of(names)
.filterKeyValue((idx, str) -> str.length() <= idx+1)
.values().toList();
Here we create an EntryStream<Integer, String>
which extends Stream<Entry<Integer, String>>
and adds some specific operations like filterKeyValue
or values
. Also toList()
shortcut is used.