Equality is a little easier to test however. true
is equal to true
and true
is not equal to false
. Similarly "My only regret is that I have but one life to give for my country" is not equal to "I have a dream." However you might be surprised if you ran this program:
class JackAndJill {
public static void main(String args[]) {
String s1 = new String("Jack went up the hill.");
String s2 = new String("Jack went up the hill.");
if ( s1 == s2 ) {
System.out.println("The strings are the same.");
}
else if ( s1 != s2 ) {
System.out.println("The strings are not the same.");
}
}
}
The result is
The strings are not the same.