Java examples for Language Basics:String
Java String Concat
public class Main { public static void main(String args[]){ String str1 = "Hello"; String str2 = " World"; /*from w ww .j av a 2 s . c om*/ //1. Using + operator String str3 = str1 + str2; System.out.println("String concat using + operator : " + str3); //2. Using String.concat() method String str4 = str1.concat(str2); System.out.println("String concat using String concat method : " + str4); //3. Using StringBuffer.append method String str5 = new StringBuffer().append(str1).append(str2).toString(); System.out.println("String concat using StringBuffer append method : " + str5); } }