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