E
Edward A Thompson
The following code compiled fine - should it have?
public static void main(String[] args)
{
String a = "Edward";
String[] b = {"Edward"};
if(a.equals(b)) System.out.println(a + " equals " + b);
else System.out.println(a + " does not equal " + b);
}
The equals method in String calss looks for the object to be an
instance of String, which I guess String[] is . Then it does a
character by character compare of the characters in the string. It
fails (expected) but should a.equals(b)) even compile?
public static void main(String[] args)
{
String a = "Edward";
String[] b = {"Edward"};
if(a.equals(b)) System.out.println(a + " equals " + b);
else System.out.println(a + " does not equal " + b);
}
The equals method in String calss looks for the object to be an
instance of String, which I guess String[] is . Then it does a
character by character compare of the characters in the string. It
fails (expected) but should a.equals(b)) even compile?