StringBuffer append() 方法在 Java 中有何作用?
StringBuffer append() 方法会将特定参数的 String 形式追加到序列中。它是 java.lang.StringBuffer 类的某个方法。该方法会返回一个指向对象自身地址的引用。
append() 方法的基本语法如下 −
public StringBuffer append(data_type variable_name)
下面是一个示范 append() 方法用法的程序 −
示例
import java.lang.*;
public class Example {
public static void main(String[] args) {
StringBuffer s1 = new StringBuffer("The sun rises in the east ");
System.out.println("Statement : " + s1);
s1.append(true);
System.out.println("Outcome : " + s1+"
");
StringBuffer s2 = new StringBuffer("Hello ");
System.out.println("Statement : " + s2);
s2.append("World");
System.out.println("Output: " + s2+"
");
char c = 'A';
StringBuffer s3 = new StringBuffer("Apple starts with ");
System.out.println("Statement : " + s3);
s3.append(c);
System.out.println("Output : " + s3);
}
}输出
Statement : The sun rises in the east Outcome : The sun rises in the east true Statement : Hello Output: Hello World Statement : Apple starts with Output : Apple starts with A
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP