String Class repeat() Method in Java with Examples Last Updated : 28 Jan, 2021 Comments Improve Suggest changes Like Article Like Report 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. Syntax: string.repeat(count); 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 Example: Input: string = abc count = 3 Output: abcabcabc Input: string = xyz count = 0 Output: null Algorithm: Firstly, we take the input of String.Then we use the repeat() method with the number of counts we want to repeat the string. Example 1: Java // Java program to demonstrate the usage of // repeat() method import java.io.*; class GFG { public static void main (String[] args) { String string="abc"; int count=3; System.out.println("String :"+string.repeat(count)); } } OutputString :abcabcabc Example 2: Java // Java program to demonstrate the usage of // repeat() method import java.io.*; class GFG { public static void main (String[] args) { String string="xyz"; int count=0; System.out.println("string :"+string.repeat(count)); } } Outputstring : Comment More infoAdvertise with us Next Article String Class repeat() Method in Java with Examples sambhavshrivastava20 Follow Improve Article Tags : Java Technical Scripter Java Programs Technical Scripter 2020 Java-Strings Java 8 +2 More Practice Tags : JavaJava-Strings Similar Reads Java String Class strip() Method With Examples Java String Class strip() method returns a string that provides a string with all leading and trailing white spaces removed. This method is similar to the String.trim() method. There are basically 3 methods by which we can remove white spaces in a different manner. strip() Method: It returns a strin 1 min read Java Program to Replace Multiple Characters in a String In this program, we will be discussing various methods for replacing multiple characters in String. This can be done using the methods listed below: Using String.replace() methodUsing replaceAll() method Using replaceFirst() method Method 1: Using String.replace() method This method returns a new st 3 min read How to Pad a String in Java? Padding a String in Java involves adding extra characters, which may be spaces, zeros, or other given characters to the beginning or end of a string to meet a desired length. This is normally used in formatting outputs or aligning texts.Example:The String.format() method is a simple way to pad strin 3 min read How to Concatenate Multiple Strings in Java? In Java programming, there are a lot of ways to concatenate multiple strings. For this, we have taken three or more String values then we concatenate those String values by using different ways. In this article, we have used two different ways, we will explain each method with one example for a bett 2 min read How to Split a String into Equal Length Substrings in Java? In Java, splitting a string into smaller substrings of equal length is useful for processing large strings in manageable pieces. We can do this with the substring method of the loop. This method extracts a substring of the specified length from the input string and stores it in a list.Example:In the 3 min read How to Remove Duplicates from a String in Java? Working with strings is a typical activity in Java programming, and sometimes we need to remove duplicate characters from a string. In this article we have given a string, the task is to remove duplicates from it. Example Input: s = "geeks for geeks"Output: str = "geks for" Remove Duplicates From a 2 min read Reverse a String in Java In Java, reversing a string means reordering the string characters from the last to the first position. Reversing a string is a common task in many Java applications and can be achieved using different approaches. In this article, we will discuss multiple approaches to reverse a string in Java with 7 min read How to Remove Duplicates from a String in Java Using Regex ? In Java programming, Regex (regular expressions) is a very important mechanism. It can be used to match patterns in strings. Regular expressions provide a short and simple syntax for describing the patterns of the text. In this article, we will be learning how to remove duplicates from a String in J 2 min read How to Shuffle Characters in a String in Java? In this article, we will learn how to shuffle characters in a String by using Java programming. For this, we have taken a String value as input and the method is available in java.util package and this method takes a list as input. Steps to shuffle characters in a String in JavaFirst, take one Strin 2 min read Java Program to Shuffle Characters in a String Without Using Shuffle() Rearranging the order of characters, in a string can be done by shuffling them. Although the shuffle() method provided by Java's Collections class is handy there are situations where you might require approaches. In this article, we will explore techniques, for shuffling characters in a string witho 3 min read Like