Given a String s
and a char c
, I\'m curious if there exists some method of producing a List
from s
(where
Using Java 9, you can iteratively search using the last index as the starting point, and stop when no match is found:
public static List getIndexList(String s, char c) {
return IntStream.iterate(s.indexOf(c), i -> s.indexOf(c, i + 1))
.takeWhile(i -> i > -1)
.boxed()
.collect(Collectors.toList());
}
Disclaimer: I didn't test this.