Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • Last Modified:

How to add strings???--URGENT

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
Jasbir21
Asked:
Jasbir21
  • 3
1 Solution
 
jimmackCommented:
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
 
jimmackCommented:
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
 
jarasaCommented:
Hi Jasbir.

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

:c)

Javier

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

thank you

0
 
jimmackCommented:
;-)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now