Solved

How to add strings???--URGENT

Posted on 2003-12-03
5
263 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This article is in regards to the Cisco QSFP-4SFP10G-CU1M cables, which are designed to uplink/downlink 40GB ports to 10GB SFP ports. I recently experienced this and found very little configuration documentation on how these are supposed to be confi…
The recent Petya-like ransomware attack served a big blow to hundreds of banks, corporations and government offices The Acronis blog takes a closer look at this damaging worm to see what’s behind it – and offers up tips on how you can safeguard your…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

615 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