Java - repeat a String n times

Different ways to repeat a String n times

StringUtils provide method to repeat a String n times.

1
StringUtils.repeat("#", 4)

Java1.5+

1
new String(new char[4]).replace("\0", "#");

Java8

1
String.join("", Collections.nCopies( 4, "#"));

Java11 provide a repeat() method to repeat a String

1
"#".repeat(4)