El método toString() de la clase CharArrayWriter en Java convierte los datos de entrada dados en una string.
Sintaxis :
public String[] toString()
Parámetros: Este método no acepta ningún parámetro.
Valor devuelto: este método devuelve una copia de los datos de entrada.
El siguiente programa ilustra el método anterior:
Programa 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()); } }
Producción:
String : geeks for + geeks
Programa 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()); } }
Producción:
String : Gopal Dave
Referencia : https://docs.oracle.com/javase/10/docs/api/java/io/CharArrayWriter.html#toString()