Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to repeat string "n" times in java? [duplicate]

I want to be able to repeat a string of text "n" times:

Something like this -

String "X",
user input = n,
5 = n,
output: XXXXX

I hope this makes sense... (Please be as specific as possible)

like image 712
user2849489 Avatar asked Oct 05 '13 12:10

user2849489


1 Answers

str2 = new String(new char[10]).replace("\0", "hello");

note: this answer was originally posted by user102008 here: Simple way to repeat a String in java

like image 51
livanek Avatar answered Oct 12 '22 23:10

livanek