devxlogo

Repeating Text n Times via Stream.generate()

Repeating Text n Times via Stream.generate()

There are several approaches for repeating a string n times. In functional-style, we can rely on Stream.generate(), as in the following example:

String result = Stream.generate(() - TEXT)   .limit(5)    .collect((joining()));

devx-admin

Share the Post: