星期一, 11月 21, 2005

string comparison

public class stringcomparison
{
public static void main(String[] args)
{
String str1 = "I come from CYCU.";
String str2 = "I come from cycu.";
if(str1.equals(str2))
{
System.out.println(" They are equals. ");
}else
System.out.println(" They are not equals. ");

}
}

Can we do it with "=="?
ANS: NO 因為都是object,所以要比較adress是否一樣
What is the result for case-sensitive comparison?
ANS:只要是大小寫不同,即為不同的字串
What about case-insensitive?
ANS:不分大小寫


0 Comments:

張貼留言

<< Home