Related Articles

Related Articles

Scanner locale() method in Java with Examples
  • Last Updated : 12 Oct, 2018

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

en_US

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

en_US

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

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up
Recommended Articles
Page :