devxlogo

May 21, 2019

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()));