Technically, they should still be true. Strings are highly weird when checking equality, and it depends how the String was made and how you check for equality.
Example 1 "String literal":
Code:
String someString1 = "MarsChelios";
boolean equals1 = (someString1 == "MarsChelios");
boolean equals2 = someString1.equals ("MarsChelios");
Result: equals1 is true, equals2 is true
Reason: When String literals are defined, they are stored in a String Table somewhere. Any other String literal will equal true when compared to it either way because for all intents and purposes, they are the same object.
Example 2 "Instantiated Strings":
Code:
String someString1 = new String ("MarsChelios");
boolean equals1 = (someString1 == "MarsChelios");
boolean equals2 = someString1.equals ("MarsChelios");
Result: equals1 is false, equals2 is true
Reason: When Objects are instantiated, they are given a unique id, their refernce id. This is how the equality operator
check equality of objects. The instantiated
has a different id than the String literal, and so fails the equality operator check.
However, the
method of
checks the chracters in a String for equality, so the check passes here.
I've tried the posted code under JDK 1.4 and it works as expected, both are true. I would suggest reinstalling the JDK you're using if you continue to get the results you've posted.
Let me know if you need anymore clarification.
Hope this helps,
MarsChelios