RFR: 8197594 - String and character repeat

Xueming Shen xueming.shen at oracle.com
Sat Feb 17 02:12:17 UTC 2018

On 2/16/18, 5:13 PM, Stuart Marks wrote:
> Let me put in an argument for handling code points:
>> 3. public static String repeat(final int codepoint, final int count)
> Most of the String and Character API handles code points on an equal 
> footing with chars. I think this is important, as over time Unicode is 
> continuing to add supplementary characters -- those that can't be 
> represented in a Java char value. Examples abound of how such 
> characters are mishandled. Therefore, I believe Java APIs should have 
> full support for code points.
> This is a small thing, and some might consider it a rare case -- how 
> often does one need to repeat something like an emoji? The issue 
> however isn't that particular use case. Instead what's required is the 
> ability to handle *any Unicode character* uniformly, regardless of 
> whether or not it's a supplementary character. The way to do that is 
> to deal with code points, so any Java API that deals with character 
> data must also handle code points.
> If we were to add just one method:
>> 1. public String repeat(final int count)
> the workaround is to take the character, turn it into a string, and 
> call the repeat() method on it. For a 'char' value, this isn't too 
> bad, but I'd argue it isn't pretty either:
>     Character.toString(charVal).repeat(n)

How about

public static repeat(int count, char... chars)?

String.repeat(100, '*');
String.repeat(100, 'x', 'y');

and it should not be too bad and kinda consistent to have

String.repeat(n,  Character.toChars(0x12345));


More information about the core-libs-dev mailing list