I am new to java coming from python. I am wondering how can I multiply a string in java. In python, I would do the following:
str1 = "hello" str2 = str1 * 10
line 2 now matters:
#str2 == 'hellohellohellohellohellohellohellohellohellohello'
I was wondering what is the easiest way to achieve this in java. Should I use a for loop or is there a built-in method?
EDIT 1
Thank you for your responses. Since then I have found an elegant solution to my problem:
str2 = new String(new char[10]).replace("\0", "hello");
Note: this answer was originally posted by user102008 here: stack overflow
java string
Alec hewitt
source share