Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 521765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:17:02+00:00 2026-05-13T08:17:02+00:00

java.util.Locale is one of those classes where I wonder whether I’m too stupid or

  • 0

java.util.Locale is one of those classes where I wonder whether I’m too stupid or the guy who wrote it. Is Mark Davis around?

As far as I can see, this class isn’t supposed to be used. The internal cache in the class is private. The factory package private. equals() uses == to compare strings. This means that I can’t compare instances of the class for equality unless I create instances myself, put them into a cache somewhere, violating DRY.

Is this what I should do? Is there a sane explanation for this behavior???

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:17:03+00:00Added an answer on May 13, 2026 at 8:17 am

    This happens because all Strings passed to the constructors are intern()-ed. A questionable practice, but the behaviour is correct in the end.


    The 3-argument constructor is

    public Locale(String language, String country, String variant) {
        this.language = convertOldISOCodes(language);
        this.country = toUpperCase(country).intern();
        this.variant = variant.intern();
    }
    

    and then later on

    private String convertOldISOCodes(String language) { 
        // we accept both the old and the new ISO codes for the languages whose ISO 
        // codes have changed, but we always store the OLD code, for backward compatibility 
        language = toLowerCase(language).intern(); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

package net.learn2develop.PopularAttractions; import java.io.IOException; import java.util.List; import java.util.Locale; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapActivity; import com.google.android.maps.MapController;
I want to create a java.util.Locale object using the display name of the locale.
import java.io.UnsupportedEncodingException; import java.util.Locale; public final class ForeignTextDemo { public static void main(String[] args)
I have the following code: import java.io.PrintStream; import java.io.UnsupportedEncodingException; import java.util.Locale; public final class
I'm using EclipseLink in Glassfish with my JavaEE application and have some java.util.Locale-columns in
Geocoder g = new Geocoder(this, Locale.getDefault()); java.util.List<android.location.Address> result = null; // testing try{ result
http://developer.android.com/reference/java/util/Locale.html What is the difference for example between Locale FRENCH vs Locale FRANCE and
this is my code: import java.util.Calendar; import java.util.Locale; public class test { /** *
package com.testotspeech; import java.util.ArrayList; import java.util.Arrays; import java.util.Locale; import android.app.Activity; import android.os.Bundle; import android.speech.tts.TextToSpeech;
The java.util.Date toString() method displays the date in the local time zone. There are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.