Why not use codepoints() instead, then you dont need to worry about surrogates and all methods which work on char should also exist for codepoints.

(I know that’s not your point but what I am trying to say there is a reason for this API decision “char must die”. although chars() is a bit odd - maybe it’s because there is no native CharStream?)

Gruss
Bernd 
 

From: core-libs-dev <core-libs-dev-r...@openjdk.org> on behalf of Anil <1dropafl...@gmail.com>
Sent: Tuesday, September 24, 2024 2:31 PM
To: core-libs-dev@openjdk.org <core-libs-dev@openjdk.org>
Subject: Shouldn't it be easier to turn a String into a stream of chars? (perhaps the String API needs a new method)
 
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

Reply via email to