Método Writer append(char) en Java con ejemplos

El método append(char) de Writer Class en Java se usa para agregar el valor char especificado en el escritor. Este valor de char se toma como parámetro.

Sintaxis:

public void append(char charValue)

Parámetros: este método acepta un parámetro obligatorio charValue que es el valor de carácter que se agregará al escritor.

Valor devuelto: este método no devuelve ningún valor.

Los siguientes métodos ilustran el funcionamiento del método append(char):

Programa 1:

// Java program to demonstrate
// Writer append(char) method
  
import java.io.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        try {
  
            // Create a Writer instance
            Writer writer
                = new PrintWriter(System.out);
  
            // Append the char value 'A'
            // to this writer using append() method
            // This will put the charValue in the
            // writer till it is appended on the console
            writer.append('A');
  
            writer.flush();
        }
        catch (Exception e) {
            System.out.println(e);
        }
    }
}
Producción:

A

Programa 2:

// Java program to demonstrate
// Writer append(char) method
  
import java.io.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        try {
  
            // Create a Writer instance
            Writer writer
                = new PrintWriter(System.out);
  
            // Append the char value 'G'
            // to this writer using append() method
            // This will put the charValue in the
            // writer till it is appended on the console
            writer.append('G');
  
            writer.flush();
        }
        catch (Exception e) {
            System.out.println(e);
        }
    }
}
Producción:

G

Publicación traducida automáticamente

Artículo escrito por Code_r y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *