Friday, September 19, 2025
HomeLanguagesJavaLocale.Builder clearExtensions() method in Java with Examples

Locale.Builder clearExtensions() method in Java with Examples

The clearExtensions() method of java.util.Locale.Builder class in Java is used to reset this Locale.Builder’s extensions to their initial and empty state. All other values of language, scripts, variant and region remain unchanged by this method.

Syntax:

public Locale.Builder clearExtensions()

Parameter: This method do not accept any parameter.

Return Type: This method returns an Locale.Builder instance with the extensions reset to their initial and empty state.

Exception: This method do not throw any exception.

Program 1:




// 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);
    }
}


Output:

LocaleBuilder: java.util.Locale$Builder@232204a1
Clearing the extensions.
Updated LocaleBuilder: java.util.Locale$Builder@232204a1

Program 2:




// 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);
    }
}


Output:

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

Reference: https://docs.oracle.com/javase/9/docs/api/java/util/Locale.Builder.html#clearExtensions–

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32301 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6665 POSTS0 COMMENTS
Nicole Veronica
11840 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11898 POSTS0 COMMENTS
Shaida Kate Naidoo
6781 POSTS0 COMMENTS
Ted Musemwa
7056 POSTS0 COMMENTS
Thapelo Manthata
6739 POSTS0 COMMENTS
Umr Jansen
6744 POSTS0 COMMENTS