Home Tutorial Java Core Java : String Concatenation

 
 

Share on Google+Share on Google+
Java : String Concatenation
Posted on: December 1, 2012 at 12:00 AM
Advertisement
This tutorial will teach you how to concatenate two strings using example.

Java : String Concatenation

This tutorial will teach you how to concatenate two strings using example.

String concat() method :  Apart from replacing, removing splitting the string, Java also provides a method to concatenate the string, concat(). This method returns the string that represents the concatenation of the object's characters followed by the string argument's characters. It appends appends one String to the end of another.

Example :

class StringConcatenation {
public static void main(String[] args) {
String str1 = "Hello";
String str2 = "Roseindia";
String str;
str = str1.concat(str2); // Concatenation of two strings
System.out.println("After concatenation String: " + str);
}
}

Description : In this example, we have defined two string variables and pass values to the variables. Now to concatenate both the strings, we have used concat() method that takes the strings and append one string to the end of the another. You can concatenate more than two strings also.

Output :

After concatenation String: HelloRoseindia
Advertisement

Related Tags for Java : String Concatenation:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 1, 2012

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com