As Eran mentioned, Stream.of(char[])
will produce a Stream<char[]>
, not a Stream<char>
as you need it to be. There are additional methods to circumvent this. You either need an array of the boxed type Character[]
static Character[] toCharacterArray(String s) {
Character[] array = new Character[s.length()];
for(int i = 0; i < s.length(); i++) {
array[i] = s.charAt(i);
}
return array;
}
and use it like this
Stream
.of(toCharacterArray(vowelOne))
.limit(3)
.forEach(System.out::println);
Or you could use String.split("")
to create a String[]
String vowelOne = "aaebcd";
Stream
.of(vowelOne.split(""))
.limit(3)
.forEach(System.out::println);
Both methods result in
a
a
e