There's a general advice to use Integer.valueOf(int)
instead of new Integer(int)
because of caching.
In JDK 5+, you should really use valueOf
because Integer
now caches Integer
objects between -128
and 127
and can hand you back the same exact Integer(0)
object every time instead of wasting an object construction on a brand new identical Integer
object.
How can extend the range?