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?...!!! Share on X

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?...!!! Share on X

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

Other Useful References:

Author

  • Deepak Verma

    Deepak Verma is a Test Automation Consultant and Software development Engineer for more than 10 years. His mission is to help you become an In-demand full stack automation tester. He is also the founder of Techndeck, a blog and online coaching platform dedicated to helping you succeed with all the automation basics to advanced testing automation tricks.

    http://Techndeck.com deepak.rkgit@gmail.com Verma Deepak