From a char array, I want to construct a stream to use java 8 features such as filters and maps.
char[] list = {'a','c','e'};
Stream<Character> cStream = Stream.of(list);
// Stream<Character> cStream = Arrays.stream(list);
The first method does not work (Reason: change cStream to Stream<char[]>
).
The commented line does not also work (Reason: The method stream(T[])
in the type Arrays is not applicable for the arguments (char[]
)).
I know that if char[] list
is changed to int[]
, everything works fine using IntStream
. But I do not want to convert every char[]
to int[]
each time or change into a list when I need to use stream library on char
array.