Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Difference between 'new Integer(value)' and Integer.valueOf(value)

795672May 11 2007 — edited May 11 2007
Hi,

Since being told a few months ago on this forum to use Integer.valueOf(value) over a new Integer, as its more memory efficient I have been doing this. Most often when getting values indexed with ints from a Hashtable.

I am just interested to know why this is a more preferable method, as valueOf returns an Integer object anyway.

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 8 2007
Added on May 11 2007
2 comments
429 views