Skip to content
Related Articles

Related Articles

Improve Article
CharArrayWriter toString() method in Java with examples
  • Last Updated : 01 Dec, 2020

The toString() method of the CharArrayWriter class in Java converts the given input data to a string.

Syntax:  

public String[] toString()

Parameters: This method does not accept any parameter.

Return Value: This method returns a copy of the input data. 

Below program illustrate the above method: 



Program 1:  

Java




// Java program to illustrate the
// above mentioned method
 
import java.io.*;
 
public class GFG {
    public static void main(String[] args)
        throws IOException
    {
 
        // Initializing String Witer
        CharArrayWriter geek_writer1
            = new CharArrayWriter();
 
        CharSequence char_sq1 = "geeks for + ";
        CharSequence char_sq2 = "geeks";
 
        // Use of append(CharSequence char_sq)
        geek_writer1.append(char_sq1);
        geek_writer1.append(char_sq2);
 
        // Convert it into string and print
        System.out.println("String : "
                           + geek_writer1.toString());
    }
}
Output: 
String : geeks for + geeks

 

Program 2: 

Java




// Java program to illustrate the
// above mentioned method
 
import java.io.*;
 
public class GFG {
    public static void main(String[] args)
        throws IOException
    {
 
        // Initializing String Witer
        CharArrayWriter geek_writer1
            = new CharArrayWriter();
 
        CharSequence char_sq1 = "Gopal ";
        CharSequence char_sq2 = "Dave";
 
        // Use of append(CharSequence char_sq)
        geek_writer1.append(char_sq1);
        geek_writer1.append(char_sq2);
 
        // Convert it into string and print
        System.out.println("String : "
                           + geek_writer1.toString());
    }
}
Output: 
String : Gopal Dave

 

Reference: https://docs.oracle.com/javase/10/docs/api/java/io/CharArrayWriter.html#toString()
 

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :