Java Utility Library

Java Locale - hasExtensions() Method



The java.util.Locale.hasExtensions() method is used to check if this locale has any extensions. The method returns true if this Locale has any extensions.

Syntax

public boolean hasExtensions()

Parameters

No parameter is required.

Return Value

Returns true if this Locale has any extensions.

Exception

NA.

Example:

In the example below, the java.util.Locale.hasExtensions() method is used to check if the given locale has any extensions.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a locale
    Locale loc = new Locale("EN", "UK");

    //printing the locale
    System.out.println("loc is: " + loc);

    //checking if the locale has any extensions
    System.out.println("Locale has any extensions?: " + loc.hasExtensions());
  }
}

The output of the above code will be:

loc is: en_UK
Locale has any extensions?: false

❮ Java.util - Locale