The strKeyword
will be repeated according to the loop. How can I Save the outcome as a new string. For example if the work "hello" was repeated twice, how would I now create the "hellohello" as a completely new string.
for (int l = 0; l < newKeywordLength; l++) {
System.out.print(strKeyword);
}
Jaroslaw Pawlak
5,5887 gold badges32 silver badges57 bronze badges
-
Eclipse has something to do here?lkanab– lkanab2015年10月29日 14:48:17 +00:00Commented Oct 29, 2015 at 14:48
2 Answers 2
string newWord="";
for (int l=0; l<newKeywordLength; l++){
newWord+=strKeyword;
}
System.out.print(newWord);
Sign up to request clarification or add additional context in comments.
Comments
just use
strKeyword+=strKeyword;
since java 6 well optimized, no need for a stringbuilder
answered Oct 29, 2015 at 14:45
1 Comment
Rene M.
You got the one up for the advice that the compiler will optimize this starting with java 6.
lang-java