CharArrayWriter toString() method in Java with examples
The toString() method of the CharArrayWriter class in Java converts the given input data to a string.
Syntax:
public char[] toCharArray()
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 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()); } } |
chevron_right
filter_none
Output:
String : geeks for + geeks
Program 2:
// 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()); } } |
chevron_right
filter_none
Output:
String : Gopal Dave
Reference: https://docs.oracle.com/javase/10/docs/api/java/io/CharArrayWriter.html#toString()
Recommended Posts:
- CharArrayWriter close() method in Java with examples
- CharArrayWriter size() method in Java with examples
- CharArrayWriter flush() method in Java with examples
- CharArrayWriter reset() method in Java with examples
- CharArrayWriter toCharArray() method in Java with examples
- IntSummaryStatistics toString() method in Java with Examples
- LocalDateTime toString() method in Java with Examples
- OffsetTime toString() method in Java with examples
- ShortBuffer toString() method in Java with Examples
- Level toString() method in Java with Examples
- ChronoLocalDateTime toString() method in Java with Examples
- Year toString() method in Java with Examples
- Optional toString() method in Java with examples
- StringWriter toString() method in Java with Examples
- Date toString() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



