Java CharArrayWriter toCharArray() Example

CharArrayWriter class toCharArray() method example. This example shows you how to use toCharArray() method.


Syntax is : public char[] toCharArray()
This method returns  an array of chars copied from the input data.

Here is the code.
/**
 * @(#) ToCharArrayCharArrayWriter.java
 * A class representing use of method toCharArray() of CharArrayWriter() class 
 in java.io Package.
 * @Version  03-May-2008
 @author   Rose India Team
 */
import java.io.*;
public class ToCharArrayCharArrayWriter {
    public static void main(String[] args){

    char[] arrChar = new char[14];
    String charSequence  = "MAHENDRA SINGH";
        // Create object of CharArrayWriter class.
        CharArrayWriter objCharArrWriter = new CharArrayWriter();

        // append() method call.
        objCharArrWriter.append(charSequence, 014);
        System.out.println("Elements in char buffer is : " + objCharArrWriter);

    // toCharArray() method call.
        arrChar = objCharArrWriter.toCharArray();
    System.out.println("buffer is seccussfully copied to character array.");
        System.out.print("Elements in character array are : ");
    System.out.print(arrChar);
    }   
}

Output of the program.
Elements in char buffer is : MAHENDRA SINGH
buffer is seccussfully copied to character array.
Elements in character array are : MAHENDRA SINGH

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US