Here is the shortest version (Java 1.5+ required):

repeated = new String(new char[n]).replace("\0", s);

Where n is the number of times you want to repeat the string and s is the string to repeat.

No imports or libraries needed.

Answer from user102008 on Stack Overflow
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › lang › String.html
String (Java SE 17 & JDK 17)
April 21, 2026 - Returns a string whose value is the concatenation of this string repeated count times.
Discussions

Can I multiply strings in Java to repeat sequences? - Stack Overflow
I have something like the following: int i = 3; String someNum = "123"; I'd like to append i "0"s to the someNum string. Does it have some way I can multiply a string to repeat it like Python doe... More on stackoverflow.com
🌐 stackoverflow.com
What is the simple way to repeat a string in Java?

You could use Apache commons-lang (which has an impressive collection of handy string utilities):

StringUtils.repeat(3, "abc")

If you're using Java 8:

Collections.nCopies(3, "abc").collect(Collectors.joining(""));
More on reddit.com
🌐 r/java
6
0
October 9, 2014
This Minecraft Seed Makes Everything Repeat

The seeds (Note you can add multiples of 2^48 to these seeds to get more):

(1,1)

102496288339226

243233776694554

25503018638468

166240506993796

194863804823673

54126316468345

180285425070967

39547936715639

229379390903807

88641902548479

11631417851241

152368906206569

278457215087719

137719726732391

60743603216145

201481091571473

74753121498560

215490609853888

123866381128776

264603869484104

187592346697722

46854858342394

172961353594608

32223865239280

60829983200677

201567471556005

236703458319970

95965969964642

159072574510805

18335086155477

82025653894727

222763142250055

(-1,1)

74811678275130

109996050363962

145180422452794

180364794541626

215549166630458

250733538719290

4442934097466

39627306186298

225951381575532

261135753664364

14845149042540

50029521131372

85213893220204

120398265309036

155582637397868

190767009486700

43099331928968

78283704017800

113468076106632

148652448195464

183836820284296

219021192373128

254205564461960

7914959840136

194239033000162

229423405088994

264607777177826

18317172556002

53501544644834

88685916733666

123870288822498

159054660911330

0 , 0 mineshaft seed repeating along (-1,13): 52649853323471

0 , 0 mineshaft seed repeating along (8,15): 19685303093557

All Broken Seeds

More on reddit.com
🌐 r/minecraftseeds
22
74
May 13, 2020
Is it possible to loop a jukebox on JAVA?
I don’t know anything about jukeboxes, but maybe if you put a dispenser to shoot a disc into it? It would be hard to time, but yeah, I got nothing else More on reddit.com
🌐 r/Minecraft
9
2
July 6, 2019
🌐
Java String
javastring.net › home › java string repeat() method
Java String repeat() Method
August 1, 2019 - jshell> "".repeat(10) $15 ==> "" jshell> "".repeat(0) $16 ==> "" jshell> "".repeat(-2) | Exception java.lang.IllegalArgumentException: count is negative: -2 | at String.repeat (String.java:3240) | at (#17:1) jshell> Let’s see what happens when the count is 1.
🌐
GeeksforGeeks
geeksforgeeks.org › java › string-class-repeat-method-in-java-with-examples
String Class repeat() Method in Java with Examples - GeeksforGeeks
December 23, 2025 - The repeat() method in Java is used to create a new string by repeating the original string a specified number of times.
🌐
Baeldung
baeldung.com › home › java › java string › generating a java string of n repeated characters
Generating a Java String of N Repeated Characters | Baeldung
January 8, 2024 - In this article, we saw various solutions for generating a string of N repeated characters. The easiest of these is String.repeat, available from JDK 11 onwards. For earlier versions of Java there are many other possible available options.
🌐
HowToDoInJava
howtodoinjava.com › home › java 11 › string repeat() – repeat string n times in java
String repeat() - Repeat string N times in Java
October 1, 2022 - Learn to repeat a given string N times, to produce a new string which contains all the repetitions, though a simple Java program using String.repeat() api.
Find elsewhere
🌐
Java2Blog
java2blog.com › home › core java › string › repeat string n times in java
Repeat String N times in Java [8 ways] - Java2Blog
September 26, 2022 - The syntax of the method is : public static String format(String format, Object... args) ... In the format() method we pass the String as a text to format a number 0 to repeat N times.
🌐
Educative
educative.io › answers › what-is-stringutilsrepeat-in-java
What is StringUtils.repeat() in Java?
the methods in Java that can be called without creating an object of the class. method of the StringUtils class that is used to repeat a given string/character a number of times to form a new string.
🌐
OpenJDK
bugs.openjdk.org › browse › JDK-8302686
Add repeat methods to StringBuilder/StringBuffer
Add the ability to repeatedly append char/code point and CharSequence data to StringBuilder/StringBuffer.
🌐
Tutorialspoint
tutorialspoint.com › java › lang › string_repeat.htm
Java - String repeat() Method
This method returns a new string whose value is the concatenation of this String repeated count of times. If the count is zero or the string is empty, the empty string is returned.
🌐
Medium
medium.com › @AlexanderObregon › javas-string-repeat-method-explained-227a93965db2
Java’s String.repeat() Method Explained | Medium
November 24, 2024 - Learn how Java's String.repeat() method works, with examples for creating patterns, padding, and formatting. Explore creative ways to use this feature.
🌐
OneCompiler
onecompiler.com › java › 3x46w7kek
String Repeat Advanced - Java - OneCompiler
public class HelloWorld { public static void main(String[] args) { String str = "test"; System.out.println("Passing n = 0 will return empty string" + str.repeat(0)); String oneTimeRepeatedString = str.repeat(1); System.out.println("Passing n = 1 will return referenec to this string " + oneTimeRepeatedString); System.out.println("Checking if reference are equal by str == oneTimeRepeatedString " + (oneTimeRepeatedString == str) ); try { System.out.println("Passing n < 0 will throw IllegalArgumentException" + str.repeat(-1)); } catch(Exception e) { System.out.println(e); } try { System.out.printl
🌐
javaspring
javaspring.net › blog › java-string-repeat
Java String Repeat: A Comprehensive Guide — javaspring.net
For example, if we have the string "abc" and we want to repeat it 3 times, the resulting string would be "abcabcabc". Java 11 introduced a new method called repeat in the String class.
🌐
Reddit
reddit.com › r/java › what is the simple way to repeat a string in java?
r/java on Reddit: What is the simple way to repeat a string in Java?
October 9, 2014 - With higher values you can take your breakfast and you still have to wait for your result. For a better result you should use the StringBuilder. Your RepeatStringMethod with the StringBuilder could look like this:
🌐
TheLinuxCode
thelinuxcode.com › home › string.repeat() in java: practical examples, edge cases, and real-world patterns (2026)
String.repeat() in Java: Practical Examples, Edge Cases, and Real-World Patterns (2026) – TheLinuxCode
February 3, 2026 - It creates a new string by repeating the original string count times, concatenated together. If count is 0, you get an empty string (""). If the original string is empty, you also get an empty string. If count is negative, Java throws an exception.
🌐
LabEx
labex.io › tutorials › java-how-to-repeat-a-string-n-times-117448
How to Repeat a String N Times in Java | LabEx
Learn three ways to repeat a string N times in Java, including the Java 11 repeat() method, the String Constructor, and the replace() method.
🌐
Java Concept Of The Day
javaconceptoftheday.com › home › java new string methods – from java 8 to java 17
Java New String Methods - From Java 8 To Java 17
February 26, 2022 - public class Java11StringMethods { public static void main(String[] args) { System.out.println("1".repeat(5)); System.out.println("abc".repeat(3)); System.out.println("1a2b3c".repeat(2)); } }
🌐
Edureka Community
edureka.co › home › community › categories › java › what is a simple way to repeat a string in java
What is a simple way to repeat a string in java | Edureka Community
August 27, 2018 - I'm looking for a simple commons method or operator that allows me to repeat some String n times. I ... the number of places a bug hunter has to look.