[11] RFR: 4993841: (str) java.lang.Character should have a toString(int) method

Stuart Marks stuart.marks at oracle.com
Sat Mar 3 01:30:01 UTC 2018


On 3/2/18 4:42 PM, Remi Forax wrote:
> Just to be sure, it now means that a code like this will work
> 
>    String s = "hello".chars()
>          .mapToObj(Character::toString)
>          .collect(Collectors.joining());

Yes, this will work, as Naoto mentioned, but I don't recommend it -- this will 
split up surrogate pairs. Simplying joining them back together will work in this 
case, but if any intermediate processing is done, it could be lossy.

I think the more important case is something like this:

     String s = "hello\ud83d\ude1d".codePoints()
         .mapToObj(Character::toString)
         .collect(joining());

Previously, you had to do something like

     String s = "hello\ud83d\ude1d".codePoints()
         .mapToObj(cp -> new String(Character.toChars(cp)))
         .collect(joining());

which is a mouthful and which also creates an extra array.

s'marks




> 
> Rémi
> 
> ----- Mail original -----
>> De: "naoto sato" <naoto.sato at oracle.com>
>> À: "Stuart Marks" <stuart.marks at oracle.com>, "Xueming Shen" <xueming.shen at gmail.com>, "core-libs-dev"
>> <core-libs-dev at openjdk.java.net>
>> Envoyé: Vendredi 2 Mars 2018 03:47:51
>> Objet: [11] RFR: 4993841: (str) java.lang.Character should have a toString(int) method
> 
>> Hi,
>>
>> Please review the fix to the following issue:
>>
>> https://bugs.openjdk.java.net/browse/JDK-4993841
>>
>> The proposed changeset is located at:
>>
>> http://cr.openjdk.java.net/~naoto/4993841/webrev.03/
>>
>> This stems from the recent discussion regarding String.repeat().[1] The
>> corresponding CSR has already been approved.
>>
>> Naoto
>>
>> --
>> [1]
>> http://mail.openjdk.java.net/pipermail/core-libs-dev/2018-February/051568.html


More information about the core-libs-dev mailing list