0

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);
}
1
  • Eclipse has something to do here? Commented Oct 29, 2015 at 14:48

2 Answers 2

1
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

1

just use

strKeyword+=strKeyword;

since java 6 well optimized, no need for a stringbuilder

1 Comment

You got the one up for the advice that the compiler will optimize this starting with java 6.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.