The locale() method of java.util.Scanner class returns this scanner's locale.
Syntax:
Java
Java
public Locale locale()Parameters: The function does not accepts any parameter. Return Value: This function returns this scanner's locale Below programs illustrate the above function: Program 1:
// Java program to illustrate the
// locale() method of Scanner class in Java
// without parameter
import java.util.*;
public class GFG1 {
public static void main(String[] argv)
throws Exception
{
String s = "Gfg Geeks GeeksForGeeks";
// create a new scanner
// with the specified String Object
Scanner scanner = new Scanner(s);
// print the locale
System.out.println(scanner.locale());
scanner.close();
}
}
Output:
Program 2:
en_US
// Java program to illustrate the
// locale() method of Scanner class in Java
// without parameter
import java.util.*;
public class GFG1 {
public static void main(String[] argv)
throws Exception
{
String s = "121324";
// create a new scanner
// with the specified String Object
Scanner scanner = new Scanner(s);
// print the locale
System.out.println(scanner.locale());
scanner.close();
}
}