Simple way to repeat a string
“. “.repeat(7) // Seven period-with-space pairs: . . . . . . . New in Java 11 is the method String::repeat that does exactly what you asked for: String str = “abc”; String repeated = str.repeat(3); repeated.equals(“abcabcabc”); Its Javadoc says: /** * Returns a string whose value is the concatenation of this * string repeated … Read more