Write a program Count String Using Java - Technology369kk

Program:

public class StringCount {
public static void main(String arg[]){
String str1 = "Hello";
String str2 ="World";

// 1. Using + operator
String str3 = str1 +str2;
System.out.println("Sting concate using + operator:"+str3);

// 2. Using string.concate() method
String str4 = str1.concat(str2);
System.out.println("String concat using String concate 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);
}
}


Answer:


Sting concate using + operator:HelloWorld
String concat using String concate method:HelloWorld
String concat using StringBuffer append method: HelloWorld
 


Post a Comment

0 Comments