Java.util.Locale.setDefault() Method

Advertisements


Description

The java.util.Locale.setDefault(Locale newLocale) method sets the default locale for this instance of the Java Virtual Machine. This does not affect the host locale.

Declaration

Following is the declaration for java.util.Locale.setDefault() method

public static void setDefault(Locale newLocale)

Parameters

  • newLocale -- the new default locale

Return Value

This method returns a hash code value for this object.

Exception

  • SecurityException -- if a security manager exists and its checkPermission method doesn't allow the operation.

  • NullPointerException -- if newLocale is null

Example

The following example shows the usage of java.util.Locale.setDefault() method.

package com.tutorialspoint;

import java.util.*;

public class LocaleDemo {

   public static void main(String[] args) {

      // create a new locale
      Locale locale1 = new Locale("en", "US", "WIN");

      // print locale
      System.out.println("Locale:" + locale1);

      // set another default locale
      Locale.setDefault(new Locale("fr", "FRANCE", "MAC"));

      // create a new locale based on new default settings
      Locale locale2 = Locale.getDefault();

      // print the new locale
      System.out.println("Locale::" + locale2);
   }
}

Let us compile and run the above program, this will produce the following result:

Locale:en_US_WIN
Locale::fr_FRANCE_MAC



Advertisements
Advertisements