El método append(CharSequence) de la clase StringWriter en Java se usa para escribir la CharSequence especificada en el escritor. Este valor de CharSequence se toma como parámetro.
Sintaxis:
public StringWriter append(CharSequence charSequence)
Parámetros: este método acepta un parámetro obligatorio charSequence que es la CharSequence que se escribirá en el escritor.
Valor de retorno: este método devuelve esta instancia de StringWriter.
Los siguientes programas ilustran el funcionamiento del método append(CharSequence):
Programa 1:
// Java program to demonstrate // StringWriter append(CharSequence) method import java.io.*; class GFG { public static void main(String[] args) { try { // Create a StringWriter instance StringWriter writer = new StringWriter(); // Write the CharSequence 'GeeksForGeeks' // to this writer using append() method // This will put the charSequence in the writer // till it is printed on the console writer.append("GeeksForGeeks"); System.out.println(writer.toString()); } catch (Exception e) { System.out.println(e); } } }
Producción:
GeeksForGeeks
Programa 2:
// Java program to demonstrate // StringWriter append(CharSequence) method import java.io.*; class GFG { public static void main(String[] args) { try { // Create a StringWriter instance StringWriter writer = new StringWriter(); // Write the CharSequence 'GFG' // to this writer using append() method // This will put the charSequence in the writer // till it is printed on the console writer.append("GFG"); writer.flush(); } catch (Exception e) { System.out.println(e); } } }
Producción: