Solved

How to add strings???--URGENT

Posted on 2003-12-03
5
259 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
java.util.concurrent.Callable way of creating threads 2 110
maven project in eclipse 11 60
reflections, dynamic class loading 3 75
some methods private some are not 8 220
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Building a successful professional career is a long and difficult journey, especially in case if your decisions are not chosen carefully. For example, if you think that you can get to the desired position without experience and apply for it, your ch…

820 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