D
David
class CompStr {
public static void main(String[] args) {
compare("first", "first");
compare("first", "second");
}
static void compare(String a,String b) {
System.out.println(a+"=="+b+": "+ a==b);
System.out.println(a+"!="+b+": "+ a!=b);
System.out.println(a+"="+b+": "+ a.equals(b));
}
}
i write this code for testing string comparision, however, when i execute
it,
System.out.println(a+"!="+b+": "+ a!=b);
System.out.println(a+"="+b+": "+ a.equals(b));
just output its boolean value, why.
the most interesting is when i change System.out.println(a+"=="+b+": "+
a==b)//--output value is false--// into System.out.println(a==b),the output
is true,
why is that???
public static void main(String[] args) {
compare("first", "first");
compare("first", "second");
}
static void compare(String a,String b) {
System.out.println(a+"=="+b+": "+ a==b);
System.out.println(a+"!="+b+": "+ a!=b);
System.out.println(a+"="+b+": "+ a.equals(b));
}
}
i write this code for testing string comparision, however, when i execute
it,
System.out.println(a+"!="+b+": "+ a!=b);
System.out.println(a+"="+b+": "+ a.equals(b));
just output its boolean value, why.
the most interesting is when i change System.out.println(a+"=="+b+": "+
a==b)//--output value is false--// into System.out.println(a==b),the output
is true,
why is that???