Solved

How to add strings???--URGENT

Posted on 2003-12-03
5
258 Views
Last Modified: 2010-04-01
Hi,
 
  I have a string like this:

String message="";



How to add string , i mean ??

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

message+=rs.getString("skill");
message+="blah....";

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

thanks you for ....Teacher. blah...
0
Comment
Question by:Jasbir21
  • 3
5 Comments
 
LVL 15

Accepted Solution

by:
jimmack earned 100 total points
ID: 9866714
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(rs.getString("skill"));
message.append(".  blah...");

The actual result is then accessed with:

message.toString().

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

Expert Comment

by:jimmack
ID: 9866730
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.  ");

System.out.println(message.toString());

would give:

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

0
 
LVL 6

Expert Comment

by:jarasa
ID: 9866984
Hi Jasbir.

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

:c)

Javier

0
 

Author Comment

by:Jasbir21
ID: 9867537
...thanks, i do appreaciate the advice..i am beginner in jsp...

thank you

0
 
LVL 15

Expert Comment

by:jimmack
ID: 9867539
;-)
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Exception creating bean of class 5 185
Servlet Login session time and authentication using Filter 6 69
caughtSpeeding java challenge 16 137
jsp login check 12 32
When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
This problem is more common than not and I will show you some things to check to solve this problem.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question