java字符串重复_在java中重复字符串的简单方法

从Java 11开始,有个方法String::repeat这正是你所要求的:String str = "abc";String repeated = str.repeat(3);repeated.equals("abcabcabc");/**

* Returns a string whose value is the concatenation of this

* string repeated {@code count} times.

* If this string is empty or count is zero then the empty

* string is returned.

*

* @param count number of times to repeat

*

* @return A string composed of this string repeated

* {@code count} times or the empty string if this

* string is empty or count is zero

*

* @throws IllegalArgumentException if the {@code count} is

* negative.

*

* @since 11

*/


版权声明:本文为weixin_28909161原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。