Find the first unique character in a string
One alternative is to let String.indexOf(int, int) do the iteration for you:

return IntStream.range(0, input.length())
                .filter(i -&gt; input.indexOf(input.charAt(i), i + 1) == -1)
                .mapToObj(i -&gt; Character.valueOf(input.charAt(i)))
                .findFirst().orElseThrow(NoUniqueCharactersException::new);



Loop with IntStream from 0 (inclusive) to the length of input (exclusive).
Filter for indices i where input.indexOf(input.charAt(i), i + 1) gives -1, i.e. there is no occurrence of the character at index i past that position.
For any matches, convert to our desired Character wrapper class using mapToObj().
In order to return the first character, we findFirst() from the IntStream, orElseThrow() our custom NoUniqueCharactersException.


A second alternative is to use String.lastIndexOf(int):

// instead of this
// .filter(i -&gt; input.indexOf(input.charAt(i), i + 1) == -1)
// use this
.filter(i -&gt; i == input.lastIndexOf(input.charAt(i)))


In this case, if the last index of the character at position i is indeed i, that means we have found our unique character.