java repeat是什么?让我们一起来了解一下吧!
Javarepeat是通过使用简单的Java程序,学习重复给定字符串N次,以创造含有所有重复的新字符串。使用方法sting.repeat(N)和使用常规方法该表达式可在java10中使用。
String.repeat():返回一个字符串,该字符串的值是给定字符串的重复 count 次的串联。如果字符串为空或 count 为零,则返回空字符串。
/** * Parameters: * count - number of times to repeat * * Returns: * A string composed of this string repeated count times or the empty string if this string is empty or count is zero * * Throws: * IllegalArgumentException - if the count is negative.*/
实战演练,具体步骤如下:
str = "IncludeHelp" //"IncludeHelp" str.repeat(3) //"IncludeHelpIncludeHelpIncludeHelp" str.repeat(0) //"" str.repeat(str.length) //"IncludeHelpIncludeHelpIncludeHelpIncludeHelpIncludeHelpIncludeHelpIncludeHelpIncludeHelpIncludeHelpIncludeHelpIncludeHelp" str.repeat(-1) /* VM424:1 Uncaught RangeError: Invalid count value at String.repeat () at :1:5 */
以上就是小编今天的分享了,希望可以帮助到大家。