setdefault
语言环境类setDefault()方法 (Locale Class setDefault() method)
- setDefault() method is available in java.util package. - setDefault()方法在java.util包中可用。 
- setDefault() method is used to assign the default locale for this Locale instance of the JVM. - setDefault()方法用于为此JVM的Locale实例分配默认语言环境。 
- setDefault() method is a static method, it is accessible with the class name and if we try to access the method with the class object then we will not get an error. - setDefault()方法是一个静态方法,可以使用类名进行访问,如果尝试使用类对象访问该方法,则不会收到错误。 
- setDefault() method may throw an exception at the time of setting locale. - setDefault()方法在设置区域设置时可能会引发异常。 - SecurityException: This exception may throw when its SecurityException :如果其checkePermission() method does not permit to operate.checkePermission()方法不允许操作,则可能引发此异常。
- NullPointerException: This exception may throw when the given parameter is null exists.NullPointerException :当给定参数为null时,可能引发此异常。
 
Syntax:
句法:
    public static void setDefault(Locale lo);
Parameter(s):
参数:
- Locale lo – represents the newly assigned default locale. - 语言环境lo –表示新分配的默认语言环境。 
Return value:
返回值:
The return type of the method is void, it returns nothing.
该方法的返回类型为void ,不返回任何内容。
Example:
例:
// Java program to demonstrate the example 
// of void setDefault(Locale lo) method of Locale 
import java.util.*;
public class SetDefaultOfLocale {
public static void main(String[] args) {
// Instantiates Locales
Locale def = Locale.getDefault();
Locale set_def = new Locale("jap", "JAPAN");
// Display Locale
System.out.println("default locale: " + def);
// By using setDefault() method is
// to set the default locale
Locale.setDefault(set_def);
System.out.println("Locale.setDefault(set_def): " + Locale.getDefault());
}
}
Output
输出量
default locale: en_US
Locale.setDefault(set_def): jap_JAPAN
翻译自: https://www.includehelp.com/java/locale-setdefault-method-with-example.aspx
setdefault