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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:58:24+00:00 2026-05-23T09:58:24+00:00

Why is java.lang.Integer.valueOf a flyweight pattern? I tried to find the reason but wasn’t

  • 0

Why is java.lang.Integer.valueOf a flyweight pattern?
I tried to find the reason but wasn’t able to.

  • 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-23T09:58:24+00:00Added an answer on May 23, 2026 at 9:58 am

    If we look at the source for valueOf, we can get a hint:
    Source of java.lang.Integer lines 638-643:

    public static Integer valueOf(int i) {
            assert IntegerCache.high >= 127;
            if (i >= IntegerCache.low && i <= IntegerCache.high)
                 return IntegerCache.cache[i + (-IntegerCache.low)];
             return new Integer(i);
    }
    

    It looks like the Integer class maintains a cache of Integer objects for common values. Rather than make a new one every time somebody asks for valueOf, it just returns a reference to one that already exists. Therefore, if you call Integer.valueOf(1) multiple times, you’ll end up getting the same object back every time (not just equivalent objects).

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

Sidebar

Related Questions

This the exception: java.lang.IllegalStateException: this kind of handler cannot be attached to multiple components;
somewhere in here I'm using java.rmi.server.UID which is upsetting GAE. After :only'ing my dependencies
hi all i want to use where clause in the query in android my
I'm writing a module which serializes others and I've got everything working only I'm
I'm learning Clojure and am confused by the following: (vector "1") ;; returns ["1"]
So, my doctor asking me to implement treeSort() and then test it on int[1000000]
I am using the AsyncTask and I am getting the following error in the
I have an app that does a query to a database.....asking for GPS data
I need to generate dynamic count of columns in me report. So I set
this is a follow-up question to my question earlier this day . I have

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.