Java String concat()


You can concatenation two strings using the concat() method shown here:

String concate(String str)

This method creates a new object that contains the contents of the string attached to the end. The concat() method performs the same function as +. For example,

String str1 = "first";
String str2 = s1.concat("second");

Puts the string "firstsecond" in str2. It produces the same results as the following sequence:

String str1 = "first";
String str2 = s1 + "second";

Example

Program
// String Concatenation
class Concatenation
{
 String _firstName;
 String _lastName;
 Concatenation(String firstName,String lastName)
 {
  this._firstName=firstName;
  this._lastName=lastName;
 }
 void PrintFullName()
 {
  System.out.println("Full Name : " + this._firstName+" "+this._lastName);
 }
}
public class Main 
{
  public static void main(String[] args) 
  {
    Concatenation c1=new Concatenation("chandan","payra");
    c1.PrintFullName();
  }
}