String Comparison
public class StringComparison
{
public static void main(String[] args) {
String s1 = "I come from CYCU.";
String s2 = "I come from cycu.";
if (s1.equals(s2)) {
System.out.println("they are equal strings.");
} else
System.out.println("they are not equal strings.");
}
}
Can we do it with "=="?
Ans:NO,都是object比較其address是否相同
What is the result for case-sensitive comparison?
Ans:區分字串的大小寫,只要大小寫不同,則視為不同字串
What about case-insensitive?
Ans:不區分大小寫
0 Comments:
張貼留言
<< Home