append(): This method is available in java.lang.StringBuffer class of Java.
Appends the string representation of the Object argument. The overall effect is exactly as if the argument were converted to a string by the method.
Parameters: obj an Object.
Returns: a reference to this object.
For Example:
The object is of any type like boolean, char, char array, CharSequence, double, float, int, long, String, and StringBuffer.
Approach
Java
public class AppendStringBuffer {public static void main(String[] args) {StringBuffer str = new StringBuffer();// append the boolean valuestr.append(false);System.out.println("After boolean = " + str);// append the char valuestr.append('a');System.out.println("After char = " + str);//// append the char arraychar arr[] = { 'a', 'b' };str.append(arr);System.out.println("After char array = " + str);// append the CharSequence valueCharSequence s = "abc";str.append(s);System.out.println("After CharSequence = " + str);// append the double valuedouble d = 16.78;str.append(d);System.out.println("After double = " + str);// append the float valuefloat f = 12.34f;str.append(f);System.out.println("After float = " + str);// append the int valueint i = 5;str.append(i);System.out.println("After int = " + str);// append the long valuelong lng = 1999191;str.append(lng);System.out.println("After long = " + str);// append the String valueString str1 = "Hello";str.append(str1);System.out.println("After String = " + str);// append the StringBuffer valueStringBuffer sb = new StringBuffer("World");str.append(sb);System.out.println("After StringBuffer = " + str);}}
Output:
After boolean = false After char = falsea After char array = falseaab After CharSequence = falseaababc After double = falseaababc16.78 After float = falseaababc16.7812.34 After int = falseaababc16.7812.345 After long = falseaababc16.7812.3451999191 After String = falseaababc16.7812.3451999191Hello After StringBuffer = falseaababc16.7812.3451999191HelloWorld
No comments:
Post a Comment