Java 中的 append 方法是什麼?
java.lang.StringBuffer 的 append(char c) 方法會將 char 引數的字串表示形式追加到該序列中。該引數會追加到該序列的內容中。該序列的長度會增加 1。
示例
import java.lang.*; public class StringBufferDemo { public static void main(String[] args) { StringBuffer buff = new StringBuffer("tuts "); System.out.println("buffer = " + buff); // appends the char argument as string to the string buffer. buff.append('A'); // print the string buffer after appending System.out.println("After append = " + buff); buff = new StringBuffer("abcd "); System.out.println("buffer = " + buff); // appends the char argument as string to the string buffer. buff.append('!'); // print the string buffer after appending System.out.println("After append = " + buff); } }
輸出
buffer = tuts After append = tuts A buffer = abcd After append = abcd !
廣告