<分区>
Possible Duplicate:
How do I compare strings in Java?
我可能在某个地方犯了逻辑错误,但我不知道在哪里。 即使条件似乎为 TRUE,输出始终为 FALSE
public class Test {
public static void main(String[] args) {
String str1 ="Hello world";
String str2 ="Hello world";
if (checkSubstring(str1,str2)){
System.out.println("Cool");
}
else
System.out.println("Not cool");
}
static boolean checkSubstring(String str1, String str2) {
String s1 = str1;
String s2 = str2;
if (s1.substring(4)== s2.substring(4)){
return true;
}
else
return false;
}
}