string comparison with "=" and ".equal"
public class Test {
public static void main(String[] args) {
String s1 = "hello";
String s2 = "hello";
//String s1 = new String("hello");
//String s2 = new String("hello");
if(s1 == s2) System.out.println("true");
}
}
and it printed true when i run the program. I thought s1 and s2 pointed at different memory address so it shouldn't have printed anything.
on my 2nd try, s1 and s2 are both declared as new string(after un-commenting them, and comment out the previous declaration), then it didn't print true as i expected.
how come it prints true on the first try?