Saturday, September 6, 2025
HomeLanguagesJavaScanner locale() method in Java with Examples

Scanner locale() method in Java with Examples

The locale() method of java.util.Scanner class returns this scanner’s locale.

Syntax:

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:

en_US

Program 2:




// 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();
    }
}


Output:

en_US

Reference: https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#locale()

RELATED ARTICLES

Most Popular

Dominic
32269 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6638 POSTS0 COMMENTS
Nicole Veronica
11802 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11868 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7029 POSTS0 COMMENTS
Thapelo Manthata
6704 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS