El método useLocale() de la clase java.util.Scanner establece la configuración regional de este escáner en la configuración regional especificada.
Sintaxis:
public Scanner useLocale(Locale locale)
Parámetros: la función acepta una configuración regional de parámetro obligatorio que especifica una string que indica la configuración regional que se utilizará.
Valor de retorno: la función devuelve este escáner modificado .
Excepciones: si la base es menor que Character.MIN_RADIX o mayor que Character.MAX_RADIX , se genera una IllegalArgumentException .
Los siguientes programas ilustran la función anterior:
Programa 1:
// Java program to illustrate the // Scanner useLocale() method 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); // print a line of the scanner System.out.println("Scanner String: \n" + scanner.nextLine()); // display the previous locale System.out.println("Current Lcoale: " + scanner.locale()); // change the locale of the scanner scanner.useLocale(Locale.ENGLISH); System.out.println("Changing Locale to ENGLISH"); // display the new locale System.out.println("Updated Locale: " + scanner.locale()); // close the scanner scanner.close(); } }
Producción:
Scanner String: Geeksforgeeks has Scanner Class Methods Current Lcoale: en_US Changing Locale to ENGLISH Updated Locale: en
Programa 2:
// Java program to illustrate the // Scanner useLocale() method in Java import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { String s = "Geeksforgeeks 2018"; // create a new scanner // with the specified String Object Scanner scanner = new Scanner(s); // print a line of the scanner System.out.println("Scanner String: \n" + scanner.nextLine()); // display the previous locale System.out.println("Current Lcoale: " + scanner.locale()); // change the locale of the scanner scanner.useLocale(Locale.FRENCH); System.out.println("Changing Locale to FRENCH"); // display the new locale System.out.println("Updated Locale: " + scanner.locale()); // close the scanner scanner.close(); } }
Producción:
Scanner String: Geeksforgeeks 2018 Current Lcoale: en_US Changing Locale to FRENCH Updated Locale: fr
Referencia: https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#useLocale(java.util.Locale)