Thakur Sachin Singh wrote:Hi,
I need to confirm my views about valueOf() method when we do operation through Integer.
can anyone tell me that is I am going to right path? is above mentioned definition is right?
As far as I know, the Integer class caches int values from -128 to 127, with the result of a better memory optimization hence without creating an Integer each time used on of those values. The values belonging in that range are likely to be the most frequently used, therefore it makes sense.
Here you can see the source code of the method you inquired about:
code taken from
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/lang/Integer.java#Integer.valueOf%28int%29
Also autoboxing works in the same way.