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);
}
Jaroslaw Pawlak
5,5887 gold badges32 silver badges57 bronze badges
asked Oct 29, 2015 at 14:43
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);
answered Oct 29, 2015 at 14:55
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

answered Oct 29, 2015 at 14:45

1 Comment

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.