📌  相关文章
📜  Java中的 Locale.Builder clearExtensions() 方法和示例

📅  最后修改于: 2022-05-13 01:55:22.281000             🧑  作者: Mango

Java中的 Locale.Builder clearExtensions() 方法和示例

Java中Java .util.Locale.Builder 类clearExtensions()方法用于将此 Locale.Builder 的扩展重置为初始状态和空状态。语言、文字、变体和区域的所有其他值通过此方法保持不变。

句法:

public Locale.Builder clearExtensions()

参数:此方法不接受任何参数。

返回类型:此方法返回一个Locale.Builder 实例,其中扩展重置为其初始和空状态。

异常:此方法不抛出任何异常。

方案一:

// Java program to demonstrate
// the above method
  
import java.util.*;
import java.util.Locale.*;
  
public class LocaleBuilderDemo {
    public static void main(String[] args)
    {
  
        // Creating a new Locale.Builder
        Locale.Builder localeBuilder
            = new Builder();
  
        // Displaying Locale.Builder
        System.out.println("LocaleBuilder: "
                           + localeBuilder);
  
        // clearing the extensions
        // of Locale.Builder
        System.out.println("Clearing the"
                           + " extensions.");
  
        localeBuilder
            = localeBuilder.clearExtensions();
  
        // Displaying Locale.Builder
        System.out.println("Updated LocaleBuilder: "
                           + localeBuilder);
    }
}
输出:
LocaleBuilder: java.util.Locale$Builder@232204a1
Clearing the extensions.
Updated LocaleBuilder: java.util.Locale$Builder@232204a1

方案二:

// Java program to demonstrate
// the above method
  
import java.util.*;
import java.util.Locale.*;
  
public class LocaleBuilderDemo {
    public static void main(String[] args)
    {
  
        // Creating a new Locale.Builder
        Locale.Builder localeBuilder
            = new Builder();
  
        // Displaying Locale.Builder
        System.out.println("LocaleBuilder: "
                           + localeBuilder);
  
        localeBuilder
            = localeBuilder
                  .setExtension('u',
                                "ca-japanese");
  
        // Displaying Locale.Builder
        System.out.println("Extension set "
                           + "of LocaleBuilder: "
                           + localeBuilder);
  
        // clearing the extensions
        // of Locale.Builder
        System.out.println("Clearing the"
                           + " extensions.");
  
        localeBuilder
            = localeBuilder.clearExtensions();
  
        // Displaying Locale.Builder
        System.out.println("Updated LocaleBuilder: "
                           + localeBuilder);
    }
}
输出:
LocaleBuilder: java.util.Locale$Builder@232204a1
Extension set of LocaleBuilder: java.util.Locale$Builder@232204a1
Clearing the extensions.
Updated LocaleBuilder: java.util.Locale$Builder@232204a1

参考: https://docs.oracle.com/javase/9/docs/api/ Java/util/Locale.Builder.html#clearExtensions–