esuslogo
 [To advertise Java(tm) Events here, contact joris@esus.com!]
banner

Java™
by example!






New @ Esus.com


  gb  In-house search engine for better results!

  gb  Get updates with the esus.com
newsletter!









  Home 
 Browse Categories 
 Ask a Java Question 
 Help 
  For Java Tips & Tricks, subscribe to the esus.com newsletter!
Search Java Q&A, Links, API's:   adv 

How do I concatenate two Strings?
There are two ways to concatenate one string to another. The most common is to use
the (rather ambiguous) + operator:



String s1 = "Hello, ";
String s2 = "world!";
String s3 = s1 + s2;
System.out.println(s3); // prints out: Hello, world!


The String class also provides a method concat that does just the same:



String s1 = "Hello, ";
String s2 = "world!";
String s3 = s1.concat(s2);
System.out.println(s3); // prints out: Hello, world!


In the previous example, the method concat is invoked on s1. s1 remains unchanged and a completely new String
will be created. A String is immutable! Once you assigned it a value, it cannot change anymore during its lifetime.
You will always have to create a new String object.


Further Information
Author of answer: unknown

Comments to this answer are only viewable by members. Login or become a member!





Terms of Service | Privacy Policy | Contact

Copyright © 2000-2003 Esus.com - All Rights Reserved 
Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. Esus.com is independent of Sun Microsystems, Inc. All other trademarks are the sole property of their respective owners.