How to add strings???--URGENT

  I have a string like this:

String message="";

How to add string , i mean ??

message="Thank you for .....";


So, that in the message it will store like this:

thanks you for ....Teacher. blah...
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You could do it the way you suggest, but a better solution is to use a StringBuffer.

StringBuffer message = new StringBuffer("Thank you for ...");
message.append(".  blah...");

The actual result is then accessed with:


Using string concatentation (message += ...) creates lots of unnecessary String objects.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
If you need to add things to other locations in the StringBuffer, you can provide the index from which to start, eg following on from the above example:

message.insert(0, "Inserted.  ");


would give:

Inserted.  Thank you for ...Teacher. blah...

Hi Jasbir.

Try to look for a good Java Book it will save you a lot of Points.



Jasbir21Author Commented:
...thanks, i do appreaciate the advice..i am beginner in jsp...

thank you

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.