Please Review: 6984084 (str) n times repetition of character constructor for java.lang.String (original) (raw)

Stephen Colebourne scolebourne at joda.org
Wed Aug 22 14:08:17 UTC 2012


On 22 August 2012 10:46, Alan Bateman <Alan.Bateman at oracle.com> wrote:

On 21/08/2012 21:45, Jim Gish wrote:

Please review http://cr.openjdk.java.net/~jgish/6984084-jdk8-StringRepeat/ <http://cr.openjdk.java.net/%7Ejgish/6984084-jdk8-StringRepeat/>

This started in lambda, making changes to both StringJoiner and String. However, the dependence of String.repeat() on StringJoiner has been removed and the resulting non-lambda classes moved here for review. There will be a separate change and review for the StringJoiner changes in lamda-dev. On the surface then String s = "foo".repeat(5); seems nice. I just wonder whether we can get any data on usage of similar methods in commonly used libraries. Some languages such as Python have a built-ins for this, and I think C# has a ctor, just not clear (to me anyway) how often the latter or equivalent it used. Folks here might be able to jump in to indicate how often they've needed to do this and whether the common-case is a repeated char rather than String (or CharSequence). Folks here might also have ideas on getting some usage data in other libraries or languages.

I don't think this is used that often and of marginal value in the JDK. If added, perhaps it should go in the buffer/builder only.

By comparison, padding is a much useful missing JDK feature: https://github.com/apache/commons-lang/blob/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java#L4451

Stephen



More information about the core-libs-dev mailing list