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 7767907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:47:21+00:00 2026-06-01T15:47:21+00:00

Though internal, I presumed that it is safe to use ConcurrentIdentityWeakKeyHashMap generally. However, the

  • 0

Though internal, I presumed that it is safe to use ConcurrentIdentityWeakKeyHashMap generally. However, the following code:

ConcurrentIdentityWeakKeyHashMap map = new ConcurrentIdentityWeakKeyHashMap();
for(int key = 0;  key < 132; key++){
     map.put(key, key);
 }
for(int key = 0;  key < 132; key++){
     System.out.println(map.get(key));
 }

produces:

0
1
..
124
125
126
127
null
null
null
null

Is this a bug or a misconception on my side (i.e. “shouldn’t be used with Integers” or “internal use only”)?

EDIT: based on Lucianos comments, I altered the code a bit to make it hold a reference to the (I hope at least) very same Integer in the list and in the map:

 ArrayList<Integer> list = new ArrayList<Integer>(132);
 ConcurrentIdentityWeakKeyHashMap<Integer, Integer> map = new ConcurrentIdentityWeakKeyHashMap<Integer, Integer>();
 for(int key = 0;  key < 132; key++){
     Integer key2 = key;
     list.add(key2);
     map.put(key2, key2);
 }
 for(int key = 0; key < 132; key++){
     System.out.println(map.get(list.get(key)));
 }

Now, it works…

  • 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-06-01T15:47:22+00:00Added an answer on June 1, 2026 at 3:47 pm

    Integer up to 127 are precached in the Integer class, so they will never be garbage collected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the code I use to setup my TCP server internal void Initialize(int
I needed a unique internal int to use that would represent several random content
We're embarking on a new middle tier service that will allow internal client systems
I'm getting the 500 Internal Server Error by running the following script, even though
I always thought that internal class has access to all data in its external
though the code is a little long, most of them are very simple IMO.
Even though it's not part of HTTP 1.1/RFC2616 webapps that wish to force a
Even though it is possible to write generic code in C using void pointer(generic
We have an internal Java library, that for legacy reasons, needs to be compiled
I'm writing a simple web report with a simple layout for internal use. The

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.