Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Java

Locale — language and region

Locale describes the language and regional context used by locale-sensitive operations.

Version: Java SE 21; repository runtime, production runtime not attested

Syntax

import java.util.Locale;
Locale locale = Locale.US;
Locale custom = Locale.of("en", "US");

java.util.Locale identifies a language and optional region; it does not format data itself.

Locale.ROOT is language- and region-neutral. Locale.US means English in the USA, Locale.FRANCE means French in France, and Locale.ENGLISH means English without a specified region.

The Locale(String,String) constructor, for example new Locale("en", "US"), has been deprecated since Java 19. In Java SE 21, prefer Locale.of("en", "US"). Both normalize letter case but do not validate code syntax; use Locale.Builder for syntax validation.

Pass a locale explicitly rather than relying on the environment's default.

Examples

import java.util.Locale;

public class Main {
    public static void main(String[] args) {
        for (Locale locale : new Locale[] {
                Locale.ROOT, Locale.US, Locale.FRANCE, Locale.ENGLISH }) {
            System.out.println(locale.toLanguageTag());
        }
        System.out.println(Locale.of("en", "US").equals(Locale.US));
    }
}

Result

und
en-US
fr-FR
en
true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources