java - confused about String vs Integer -
this question has answer here: weird integer boxing in java 9 answers i have question comparing string , integer objects... a. comparing string references: string string1 = "hi"; system.out.printf("%s \n", string1); string originalstring = string1; system.out.printf("%-9s %-9s %b \n", string1, originalstring, originalstring == string1); system.out.println(); string1 += " there"; originalstring += " there"; system.out.printf("%-9s %-9s %b \n", string1, originalstring, originalstring.equals(string1)); system.out.printf("%-9s %-9s %b \n", string1, originalstring, originalstring == string1); produced output: hi hi hi true hi there hi there true hi there hi there false here, last line compares addresses , expecte