Shouldn't it be easier to turn a String into a stream of chars? (perhaps the String API needs a new method)

Anil 1dropaflame at gmail.com
Tue Sep 24 12:29:40 UTC 2024


I was trying to solve a puzzle (see post in JavaRanch
https://coderanch.com/t/784868/java/puzzling-partitioningBy-IntStream-compile-error
)
I found that String.chars() yields an IntStream.
Someone pointed out that to convert it into Characters, one has to do

  Stream<Character> sc = s.chars().mapToObj(n -> (char) n);

It should not take so many obscure steps like this to turn a String into a
stream of chars!
I feel the Java API needs another method

Stream<Character> String.asChars()

thanks,
Anil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20240924/e6d50a65/attachment.htm>


More information about the core-libs-dev mailing list