• August 28, 2014
  • Core Java
  • Comments Off on append(String str) StringBuffer method in java

append(String str) StringBuffer method in java

append(String str): append the specified string at the end of this string.

Syntax: public synchronized StringBuffer append(String str).

Note: if specified string is null than it append “null” string at the end.
If append has object, int, double etc as an argument than argument value first converted into string using String.valueOf()before appending.

Example:

StringBufferAppendExample.java

/**
 * This program is used to show the use of append() method.
 * @author javawithease
 */
class TestStringBuffer{
	StringBuffer sb = new StringBuffer("Hello ");
 
	/**
	 * This method is used to show the use of append() method.
	 * @author javawithease
	 */
	public void appendTest(){
		//concatenate the argument string 
                //at the end of this string.
		System.out.println(sb.append("www.javawithease.com"));
	}
}
 
public class StringBufferAppendExample {
	public static void main(String args[]){
		//creating TestStringBuffer object
		TestStringBuffer obj = new TestStringBuffer();
 
		//method call
		obj.appendTest();
	}
}

Output:

Hello www.javawithease.com

Download this example.
 
Next Topic: insert(int offset, String str) StringBuffer method in java.
Previous Topic: StringBuffer in java.

Related Topics:

StringBuffer in java.
append(String str) StringBuffer method in java.
insert(int offset, String str) StringBuffer method in java.
replace(int startIndex, int endIndex, String str) StringBuffer method in java.
delete(int startIndex, int endIndex) StringBuffer method in java.
reverse() StringBuffer method in java.
capacity() StringBuffer method in java.
ensureCapacity(int minCapacity) StringBuffer method in java.
StringTokenizer in java.

 


Comments are closed.