If we look at the source for valueOf , we can get a hint: Source of lines java.lang.Integer : 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 appears that the Integer class supports the cache of Integer objects for common values. Instead of creating a new one, every time someone asks for valueOf , it simply returns a link to an existing one. Therefore, if you call Integer.valueOf(1) several times, you will return the same object each time (and not just equivalent objects).
sshannin
source share