Java CharArrayWriter append() Example
CharArrayWriter class append() method example. This example shows you how to use append() method.
Syntax is : public CharArrayWriter append(CharSequence csq, int start, int end)
This method appends a subsequence of the specified character sequence to this writer. An invocation of this method of the form out.append(csq, start, end) when csq is not null, behaves in exactly the same way as the invocation :- out.write(csq.subSequence(start, end).toString())
Here is the code.
/**
* @(#) Append2CharArrayWriter.java
* A class representing use of method append() of CharArrayWriter() class in
java.io Package.
* @Version 31-May-2008
* @author Rose India Team
*/
import java.io.*;
public class Append2CharArrayWriter {
public static void main(String[] args){
String charSequence = "MAHENDRA";
// Create object of CharArrayWriter class.
CharArrayWriter objCharArrWriter = new CharArrayWriter();
// append() method call.
objCharArrWriter.append(charSequence, 0, 4);
System.out.println("character subsequence are appended successfully!");
System.out.print("Elements in char buffer is : " + objCharArrWriter);
}
} |
Output of the program.
character subsequence are appended successfully!
Elements in char buffer is : MAHE |
|