java.io.StringWriter.append(CharSequence csq)方法實例
java.io.StringWriter.append() 方法將指定的字符序列到這個writer。
聲明
以下是java.io.StringWriter.append()方法的聲明
public StringWriter append(CharSequence csq)
參數
-
csq -- 字符序列追加。如果csq為null,則這四個字符“null”被附加到這個writer。
返回值
此方法返回這個writer。
異常
-
NA
例子
下麵的示例演示java.io.StringWriter.append()方法的用法。
package com.yiibai; import java.io.*; public class StringWriterDemo { public static void main(String[] args) { // create a new writer StringWriter sw = new StringWriter(); // create two new sequences CharSequence sq1 = "Hello"; CharSequence sq2 = " World"; // append sequence sw.append(sq1); // print result System.out.println("" + sw.toString()); // append second sequence sw.append(sq2); // print result again System.out.println("" + sw.toString()); } }
Let us compile and run the above program, this will produce the following result
Hello Hello World