Solved

How to add strings???--URGENT

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Spring Data jpa resouce mapping error "status":500,"error":"Internal Server Error", 3 377
web application structure 18 137
servlet example 17 73
jsp error 6 72
How many times a day do you open, acknowledge, or close an IT incident? What’s your process? Do you have a process depending on the incident, systems involved, and other factors? New Relic Alerts gives you options for how you interact with notifica…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

710 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