Can one initialize a Java string with a single repeated character to a specific length [duplicate]
char[] chars = new char[len];
Arrays.fill(chars, ch);
String s = new String(chars);
StringUtils.repeat(str, count)
from apache commons-lang
Here is an elegant, pure Java, one-line solution:
Java 11+:
String str = "p".repeat(5); // "ppppp"
prior Java 11:
String str = new String(new char[5]).replace("\0", "p"); // "ppppp"