useLocale(Locale): This method is available in java.util.Scanner class of Java.
Syntax:
Scanner java.util.Scanner.useLocale(Locale locale)
This method takes one argument. This method sets this scanner's locale to the specified locale.
Parameters: One parameter is required for this method.
locale: A string specifying the locale to use.
Returns: this scanner
Exceptions: NA
Approach
Java
import java.util.Locale;import java.util.Scanner;public class ScanneruseLocale {public static void main(String[] args) {String source = "Hello World";Scanner scanner = new Scanner(source);System.out.println(scanner.useLocale(Locale.US));scanner.close();}}
Output:
java.util.Scanner[delimiters=\p{javaWhitespace}+][position=0][match valid=false][need input=false][source closed=false][skipped=false][group separator=\x{2c}][decimal separator=\x{2e}][positive prefix=][negative prefix=\Q-\E][positive suffix=][negative suffix=][NaN string=\QNaN\E][infinity string=\Q∞\E]
No comments:
Post a Comment