java.util.Scanner useLocale(Locale locale)

Description :

This java tutorial shows how to use the useLocale(Locale locale) method of Scanner class of java.util package. This method sets the Locale to be used by this Scanner object overriding the default locale.

Method Syntax :

public Scanner useLocale(Locale locale)

Parameter Input :


DataType Parameter Description
Locale locale The locale to be used by this Scanner


Method Returns :

This method simply returns this Scanner object with Locale being set as method parameter.

Compatibility Version :

Requires Java 1.5 and up

Exception :


Discussion :

The Scanner useLocale() method is helpful to set a locale specific setting which affects many elements in primitive matching regular expressions.

Java Code Example :

This java example source code demonstrates the use of useLocale(Locale locale) method of Scanner class. Basically we just set the Locale setting to our scanner class. We have used the static constant Locale.English to set the method argument Locale.

Sample Output :

Running the useLocale(Locale locale) method example source code of Scanner class will give you the following output

java scanner useLocale(locale) method example

java scanner useLocale(locale) method example

Exception Scenario :


Similar Method :

  • N/A

Suggested Reading List :

References :