Date/Time Beginner

Create language and region locales with Locale.of() instead of deprecated constructors.

✕ Deprecated constructor
Locale brazilianPortuguese =
    new Locale("pt", "BR");
✓ Java 19+
Locale brazilianPortuguese =
    Locale.of("pt", "BR");
See a problem with this code? Let us know.
✅

Supported API

Avoids deprecated constructors.

👁

Clear construction

The named factory communicates intent.

🧩

Consistent style

Matches modern JDK value-object factories.

Old Approach
Locale constructors
Modern Approach
Locale.of()
Since JDK
19
Difficulty
Beginner
Locale constructors to Locale.of()
Available

Available since JDK 19 (September 2022)

Locale factory methods replace constructors deprecated in JDK 19. The factory form is clearer, aligns with other value-based APIs, and centralizes locale creation.