[Java] equals()、equalsIgnoreCase()

equals( )
Code:
public static void main(String[] args)
{
String s1 = "hello";

if(s1.equals("hello"))
  System.out.println("s1 equals hello");
else
  System.out.println("s1 not equals hello");
}

輸出:
s1 equals hello

equalsIgnoreCase( ) 
Code:
public static void main(String[] args)
{
String s1 = "hello";
String s2 = "Hello";

if(s1.equalsIgnoreCase(s2))
  System.out.println("s1 equals s2");
else
  System.out.println("s1 not equals s2");
}
//equalsIgnoreCase會忽略大小寫

輸出:
s1 equals s2
By Hao★

留言

熱門文章

[C#] 將DataTable轉換成Html格式表格

[MS SQL] 查詢所有Procedure