I\'m running this code with JDK 1.4 and 1.5 and get different results. Why is it the case?
String str = \"\";
int test = 3;
str = String.valueOf(test);
System.o
From java 5 string.valueof() is expected to return new string. rather than intern(ed) (shared) string!
Consider following example
int test = 3;
String str = String.valueOf(test);
String str2 = String.valueOf(test);
if(str == str2)
System.out.println("valueOf return interned string");
else
System.out.println("valueOf does not return interned string");
Output in java >=5
valueOf does not return interned string
But in java 4 output is
valueOf return interned string
That explains the behavior!