This article continues a detailed description of the append() method used in the Java StringBuffer() class.
Before reading further, read the previous parts of the series.
Now let's move forward to the next append() methods to reach our purpose of learning. The next four append() methods are as in the following:

- StringBuffer append(int i) appends the string representation of the int argument to the given sequence. It returns the reference to the given object.
- StringBuffer append(long lng) appends the string representation of the long argument to the given sequence. It also returns the reference to the given object.
- StringBuffer append(float f) appends the string representation of the float argument to the given sequence. It returns the reference to the given object.
- StringBuffer append(double d) appends the string representation of the double argument to the given sequence. It also returns the reference to the given object.
Now to understand with code examples.
Example
The following example contains all four append() methods stated above.
- public class AppendIntLongFloatDoubleMethods
- {
- public static void main(String args[])
- {
- StringBuffer str1 = new StringBuffer("Ben ");
- System.out.println("Output for append(int i):");
- System.out.println();
- str1.append(10);
- System.out.println(str1); //appends int argument as string to the string buffer
- str1 = new StringBuffer("Lecture ");
- str1.append(3);
- System.out.println(str1); //appends int argument as string to the string buffer
- System.out.println();
- System.out.println("Output for append(long lng):");
- System.out.println();
- StringBuffer str2 = new StringBuffer("sum = ");
- str2.append(9632);
- System.out.println(str2); //appends long argument as string to the string buffer
- str2 = new StringBuffer("Pin Code: ");
- str2.append(284003);
- System.out.println(str2); //appends long argument as string to the string buffer
- System.out.println();
- System.out.println("Output for append(float f):");
- System.out.println();
- StringBuffer str3 = new StringBuffer("Rate of str3 = ");
- str3.append(3.147);
- System.out.println(str3); //appends float argument as string to the string buffer
- str3 = new StringBuffer("Percentage: ");
- str3.append(73.143);
- System.out.println(str3 + "%"); //appends float argument as string to the string buffer
- System.out.println();
- System.out.println("Output for append(double d):");
- System.out.println();
- StringBuffer str4 = new StringBuffer("Double rate = ");
- str4.append(60.234134);
- System.out.println(str4); //appends double argument as string to the string buffer
- str4 = new StringBuffer("Double Percentage: ");
- str4.append(5451.0001010303);
- System.out.println(str4 + "%"); //appends double argument as string to the string buffer
- }
- }
Output
Now the next and the last four append() methods are being discussed in this lecture.




Gowtham RajamanickamPosted May 19, 2015, 12:45 AM
keep writing..
Gowtham RajamanickamPosted May 19, 2015, 12:45 AM
good one
NitinPosted May 17, 2015, 2:15 PM
nice
Manoj BhoirPosted May 16, 2015, 6:04 AM
Nice Article....
Gopi ChandPosted May 16, 2015, 4:21 AM
Thanks to everyone. :)
Santhakumar MunuswamyPosted May 16, 2015, 3:44 AM
Thanks for nice article
NitinPosted May 16, 2015, 2:58 AM
nice
Abhishek JaiswalPosted May 15, 2015, 4:33 PM
Nice Presentation!! Recommended article! :)