Why the output is different between JDK 1.4 and 1.5?
问题 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.out.println("str[" + str + "]\nequals result[" + (str == "3") + "]"); if (str == "3") { System.out.println("if"); } else { System.out.println("else"); } outputs: on jdk 1.4 str[3] equals result[true] if on jdk 1.5 str[3] equals result[false] else 回答1: According to this page, the Integer#toString method (which is called by String#valueOf