Ulf Dittmer wrote:
The hint is: "2" is a frequently requested value, while "2000" is not.
When the references i and eye in the pool are compared 2==2 results in true and 2000==2000 is false since it exceeds 127.
public static Integer valueOf(int i)
Returns a Integer instance representing the specified int value. If a new Integer instance is not required, this method should generally be used in preference to the constructor Integer(int), as this method is likely to yield significantly better space and time performance by caching frequently requested values.
Both symbols ... and  cannot be used together.
Ankit Garg wrote:Well your program still doesn't gives the guaranteed behavior of the result you want. Actually you won't get the correct result most of the times. You need to do something more complicated to get reliable output