When we need to append String with java String we can using a simple Code in below
String x="test1";
x=x+"test2" ;
x=x+"test2" ;
With this code have some problem when we adding a lot of String it's not support !!
We have the best solution to append String by using StringBuffer we can append a lot of data
We have the best solution to append String by using StringBuffer we can append a lot of data
StringBuffer is a Class in paclage java.lang
Example Code for using StringBuffer
//Create instance for StringBuffer
StringBuffer stringbuffer =new StringBuffer();
//Append String to StringBuffer
stringbuffer.append("str1");
stringbuffer.append("str2");
stringbuffer.append("str3");
/*
..
.. You can append a lot of data you want
..
*/
//Transform it to String
String data=stringbuffer.toString();
System.out.println("StringBuffer data :"+data);
Out put when Run Program
StringBuffer data :str1str2str3