String Class repeat() Method in Java with Examples
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.