網站首頁 學習教育 IT科技 金融知識 旅遊規劃 生活小知識 家鄉美食 養生小知識 健身運動 美容百科 遊戲知識 綜合知識
當前位置:趣知科普吧 > IT科技 > 

repeat|java

欄目: IT科技 / 發佈於: / 人氣:2W

<link rel="stylesheet" href="https://js.how234.com/third-party/SyntaxHighlighter/shCoreDefault.css" type="text/css" /><script type="text/javascript" src="https://js.how234.com/third-party/SyntaxHighlighter/shCore.js"></script><script type="text/javascript"> SyntaxHighlighter.all(); </script>

java repeat是什麼?讓我們一起來了解一下吧!

Javarepeat是透過使用簡單的Java程序,學習重複給定字元串N次,以創造含有所有重複的新字元串。使用方法sting.repeat(N)和使用常規方法該表達式可在java10中使用。

 

java repeat
   

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*/

Tags:java repeat