The string can be repeated N number of times, and we can generate a new string that has repetitions. repeat() method is used to return String whose value is the concatenation of given String repeated count times. If the string is empty or the count is zero then the empty string is returned.
Parameter: Accepts an integer count which is the number of times we want to repeat the string.
Returns: String whose value is the concatenation of given String repeated count times
Input: string = abc count = 3 Output: abcabcabc Input: string = xyz count = 0 Output: null
- Firstly, we take the input of String.
- Then we use the repeat() method with the number of counts we want to repeat the string.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.