CharArrayWriter append(CharSequence csq, int start, int end)


描述

所述java.io.CharArrayWriter.append(CharSequence的CSQ,INT开始,INT端)方法将指定字符序列的这种写入器的部分。

声明

以下是java.io.CharArrayWriter.append(CharSequence csq,int start,int end)方法的声明

public CharArrayWriter append(CharSequence csq, int start, int end)

参数

csq - 要追加的字符序列。如果字符序列为null,则编写器附加4个字符“null”。

start - 部分中第一个字符的索引

end - 子序列结束后的字符索引

返回值

This CharArrayWriter

异常

IndexOutOfBoundsException - 如果end大于序列的长度,则start大于end,或start或end为negative。

实例

以下示例显示了java.io.CharArrayWriter.append(CharSequence csq,int start,int end)方法的用法。

package com.tutorialspoint;

  import java.io.CharArrayWriter;

  public class CharArrayWriterDemo {
     public static void main(String[] args) {      
        CharArrayWriter chw = null;

        try {
           // create character array writer
           chw = new CharArrayWriter();

           // declare character sequence
           CharSequence csq = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

           // append character sequence to the writer
           chw.append(csq, 2, 5);

           // prints out the character sequences
           System.out.println(chw.toString());

        } catch(Exception e) {
           // for any error
           e.printStackTrace();
        } finally {
           // releases all system resources from writer
           if(chw!=null)
              chw.close();
        }
     }
  }

让我们编译并运行上面的程序,这将产生以下结果

CDE