How to repeat a string n times in Java

How to repeat a string n times in Java

In this post we will give you information about How to repeat a string n times in Java. Hear we will give you detail about How to repeat a string n times in JavaAnd how to use it also give you demo for it if it is necessary.

Learn, how to repeat a string n times in Java.

Repeating a string

In Java 11, we have a built-in String.repeat() method by using that we can repeat a string n times.

Here is an example, that repeats the string ‘fox’ 5 times.

public class Main{    public static void main(String[] args)    {        String str = "fox";        String repeatedVal = str.repeat(5);        System.out.println(repeatedVal);    }}

Output:

foxfoxfoxfoxfox

Hope this code and post will helped you for implement How to repeat a string n times in Java. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US