TopBottom

Followers

Followers



Click on more
SUBSCRIBE



VIDEO

Announcement: wanna exchange links? contact me at ravikrak@yahoo.com

String Concatenation in Java

Posted by Ravi Kumar at Sunday, March 15, 2009
Share this post:
Ma.gnolia DiggIt! Del.icio.us Yahoo Furl Technorati Reddit

Strings are sequences of characters, such as "hello".
String a = ""; // an empty string
String greeting = "Hello";

Java allows you to use the + sign to join (concatenate) two strings together.
String a = "hello";
String b = "hai";
String message = a + b;
The above code makes the value of the string variable message "hellohai".

When you concatenate a string with a value that is not a string, the latter is converted to a string.
int age = 25;
String a = "hi" + age;
sets variable a to the string "hi25".

Share |

Labels:

0 comments:

Post a Comment