Search code examples
javaobjectprimitive

Are Integer, Boolean, etc. Java Objects singleton objects?


I tried to search for this but couldn't find an answer easily.

If we have multiple Integer Java objects corresponding to the same integer value--are they the same in memory?


Solution

  • No, but if you use Integer.valueOf(), Long.valueOf(), etc you may get single cached values. Not the same thing.