I have an IntStream
object that I have limited to 30 elements and I like to get a List<Character>
from all the int
elements in the stream.
Thanks in advance
You may map each int
to a char
then collect into a list, this will result in a list of character given by their ASCII code
List<Character> r = IntStream.range(50, 80).mapToObj(a -> (char) a).collect(Collectors.toList());
System.out.println(r); // [2, 3, 4, 5, 6, 7, 8, 9, :, ;, <, =, >, ?, @, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]
in this way you can do this action.
IntStream intStream = IntStream.of(1, 2, 3, 4, 5, 6, 7, 8, 9);
List<Character> characterList = intStream.mapToObj(i -> (char) i).collect(Collectors.toList());
for all streams you can do this via mapping each item to a character and collect them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With