Repeat string N times using String.repeat(N) API in Java 11

In this post, we will learn “How to repeat a string N number of times in Java 11?”. Java 11 introduced a new method called repeat(N) to do that.

Here, we are going to learn following things:

  1. What is repeat(N) method?
  2. How to use it?

How to Repeat String in Java 11?...!!! Click To Tweet

 

Let’s Begin,

1. What is repeat(N) method?

repeat(N) is a string method of String class.

This method returns a string whose value is the concatenation of this string repeated count times. If this string is empty or count is zero then the empty string is returned.

Syntax:

 

2. How to use it?

Let’s take an example where we are repeating a word ‘Techndeck’ 5 times.

 

Output:

 

How to Repeat String in Java 11?...!!! Click To Tweet

Do you like this Post? – then check my other helpful posts:

Other Useful References:

 

Related Posts:

[wcp-carousel id=”5342″]

Promotional Content:

Loading RSS Feed

Leave a Reply

Your email address will not be published.Required fields are marked *

Facebook Twitter Instagram YouTube