Java 8/9: Can a character in a String be mapped to its indices (using streams)? : <p>Given a <code>String s</code> and a <code>char c</code>, I'm curious if there exists some method of producing a <code>List&lt;Integer&gt; list</code> from <code>s</code> (where the elements within <code>list</code> represent the indices of <code>c</code> within <code>s</code>).</p>

<p>A close, but <strong>incorrect</strong> approach would be:</p>

<pre><code>public static List&lt;Integer&gt; getIndexList(String s, char c) {
    return s.chars()
            .mapToObj(i -&gt; (char) i)
            .filter(ch -&gt; ch == c)
            .map(s::indexOf) // Will obviously return the first index every time.
            .collect(Collectors.toList());
}
</code></pre>

<p>The following inputs should yield the following output:</p>

<pre><code>getIndexList("Hello world!", 'l') -&gt; [2, 3, 9]
</code></pre>
