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(); } } |
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(); } } |
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 DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Locale setDefault(Locale.Category, Locale) Method in Java with Examples
- TimeZone getDisplayName(Locale locale) Method in Java with Examples
- Locale.Builder setLocale(Locale) method in Java with Examples
- Locale getDisplayVariant(Locale inLoc) Method in Java with Examples
- Locale getDisplayName(Locale) Method in Java with Examples
- Locale getDisplayLanguage(Locale) Method in Java with Examples
- Locale getDisplayCountry(Locale) Method in Java with Examples
- Scanner hasNextFloat() method in Java with Examples
- Scanner skip() method in Java with Examples
- Scanner nextDouble() method in Java with Examples
- Scanner nextLong() method in Java with Examples
- Scanner nextInt() method in Java with Examples
- Scanner nextByte() method in Java with Examples
- Scanner nextBoolean() method in Java with Examples
- Scanner hasNextLine() method in Java with Examples
- Scanner nextFloat() method in Java with Examples
- Scanner nextLine() method in Java with Examples
- Scanner useRadix() method in Java with Examples
- Scanner nextBigInteger() method in Java with Examples
- Scanner useDelimiter() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

