Answers for "How to repeat strings in java"

0

repeat string in java

public class Main 
{
    public static void main(String[] args) 
    {
        String str = "Abc";
 
        String repeated = new String(new char[3]).replace("\0", str);
 
        System.out.println(repeated);
    }
}
Posted by: Guest on May-08-2021
0

How to repeat strings in java

//For above Java 11
public class Test 
{
    public static void main(String[] args) 
    {
        String s1 = "Hello Guys!"
        int timesToRepeat = 5;
 		
        //Sturcture: *String*.repeat(int times)
        String repeatString = s1.repeat(timesToRepeat);
 
        System.out.println(repeatString);
    }
  
  	//Will Come out as
  	//Hello Guys! Hello Guys! Hello Guys! Hello Guys! Hello Guys!
}
Posted by: Guest on October-25-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language