CodesJava

Easy learning with example program codes

append(String str) StringBuilder method in java

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

Syntax:

public StringBuilder 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:

StringBuilderAppendExample.java

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

Output:

Hello www.codesjava.com

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

 

Please follow and like us:
error
Posted in Java   








Copyright © 2019 CodesJava DMCA.com Protection Status