Saturday, September 6, 2025
HomeLanguagesJavaLocale.Builder build() method in Java with Examples

Locale.Builder build() method in Java with Examples

The build() method of java.util.Locale.Builder class in Java is used to build a Locale from the values specified to this Locale.Builder instance. This method returns a Locale instance after building it.

Syntax:

public Locale build()

Parameter: This method do not accept any parameter.

Return Type: This method returns an Locale instance with the values set to this Locale.Builder.

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();
  
        // setting the locale of Locale.Builder
        Locale locale = Locale.FRANCE;
        System.out.println("Setting the Locale: "
                           + locale);
        localeBuilder.setLocale(locale);
  
        // Displaying Locale.Builder
        System.out.println("LocaleBuilder: "
                           + localeBuilder);
  
        // Building the Locale from Locale.Builder
        System.out.println("Building the Locale.");
  
        Locale builtLocale = localeBuilder.build();
  
        // Displaying Locale.Builder
        System.out.println("Built Locale: "
                           + builtLocale);
    }
}


Output:

Setting the Locale: fr_FR
LocaleBuilder: java.util.Locale$Builder@232204a1
Building the Locale.
Built Locale: fr_FR

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();
  
        // setting the locale of Locale.Builder
        Locale locale = Locale.ENGLISH;
        System.out.println("Setting the Locale: "
                           + locale);
        localeBuilder.setLocale(locale);
  
        // Displaying Locale.Builder
        System.out.println("LocaleBuilder: "
                           + localeBuilder);
  
        // Building the Locale from Locale.Builder
        System.out.println("Building the Locale.");
  
        Locale builtLocale = localeBuilder.build();
  
        // Displaying Locale.Builder
        System.out.println("Built Locale: "
                           + builtLocale);
    }
}


Output:

Setting the Locale: en
LocaleBuilder: java.util.Locale$Builder@232204a1
Building the Locale.
Built Locale: en

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

RELATED ARTICLES

Most Popular

Dominic
32270 POSTS0 COMMENTS
Milvus
82 POSTS0 COMMENTS
Nango Kala
6639 POSTS0 COMMENTS
Nicole Veronica
11804 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11869 POSTS0 COMMENTS
Shaida Kate Naidoo
6753 POSTS0 COMMENTS
Ted Musemwa
7029 POSTS0 COMMENTS
Thapelo Manthata
6705 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS