Java StringBuffer example to append two Strings using append
By candid | Posted :
Nov 9, 2016
| Updated :
Nov 9, 2016
public StringBuffer append(String str)
Appends the specified string to this character sequence.
The characters of the String argument are appended, in order, increasing the length of this sequence by the length of the argument. If str is null, then the four characters "null" are appended.
Let n be the length of this character sequence just prior to execution of the append method. Then the character at index k in the new character sequence is equal to the character at index k in the old character sequence, if k is less than n; otherwise, it is equal to the character at index k-n in the argument str.
Program:
package com.candidjava;
public class StringBufferAppend
{
public static void main(String[] args)
{
StringBuffer sb = new StringBuffer("STUDENT");
sb.append(" MARKLIST");
System.out.println(sb);
}
}
Output:
STUDENTNAMELIST
Description:
The characters of the String argument are appended, in order, increasing the length of this sequence by the length of the argument.
If str is null, then the four characters ?null? are appended.
Let n be the length of this character sequence just prior to execution of the append method. Then the character at index k in the new character sequence is equal to the character at index k in the old character sequence, if k is less than n; otherwise, it is equal to the character at index k-n in the argument str.