El método delimiter() de la clase java.util.Scanner devuelve el patrón que este escáner está utilizando actualmente para hacer coincidir los delimitadores.
Sintaxis:
public Pattern delimiter()
Valor devuelto: la función devuelve el patrón de delimitación del escáner.
Los siguientes programas ilustran la función anterior:
Programa 1:
// Java program to illustrate the // delimiter() method of Scanner class in Java import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { String s = "Geeksforgeeks has Scanner Class Methods"; // create a new scanner // with the specified String Object Scanner scanner = new Scanner(s); // prints the next line of the string System.out.println("Scanner String: \n" + scanner.nextLine()); // print the delimiter this scanner is using System.out.println("\nDelimiter being used in Scanner: " + scanner.delimiter()); // Close the scanner scanner.close(); } }
Producción:
Scanner String: Geeksforgeeks has Scanner Class Methods Delimiter being used in Scanner: \p{javaWhitespace}+
Programa 2:
// Java program to illustrate the // delimiter() method of Scanner class in Java import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { String s = "Geeksforgeeks.has.Scanner.Class.Methods"; // create a new scanner // with the specified String Object Scanner scanner = new Scanner(s); // Set the delimiter to "." scanner.useDelimiter("."); // prints the next line of the string System.out.println("Scanner String: \n" + scanner.nextLine()); // print the delimiter this scanner is using System.out.println("\nDelimiter being used in Scanner: " + scanner.delimiter()); // Close the scanner scanner.close(); } }
Producción:
Scanner String: Geeksforgeeks.has.Scanner.Class.Methods Delimiter being used in Scanner: .
Referencia: https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#delimiter()