Java 快速導覽 - String 類別的 equalsIgnoreCase()

String 類別 (class) 有 equalsIgnoreCase() 方法 (method) ,判斷字串 (string) 是否與 anObject 相同,不考慮大小寫的分別

方法描述
boolean equalsIgnoreCase(String anotherString)判斷字串是否與 anotherString 相同,不考慮大小寫的分別


舉例如下
class EqualsignorecaseDemo {
    public static void main(String[] args) {
        String a = "Imagination is more important than knowledge.";
        String b = "He who has hope has everything.";
        String c = "台上一分鐘,台下十年功。";
        String d = "imagination is more important than knowledge.";
        String e = "He who has hope has everything.";
        String f = "台上十分鐘,台下一年功。";
        
        System.out.println(a.equalsIgnoreCase(d));
        System.out.println(b.equalsIgnoreCase(e));
        System.out.println(c.equalsIgnoreCase(f));
    }
}

/* 《程式語言教學誌》的範例程式
    http://pydoing.blogspot.com/
    檔名:EqualsignorecaseDemo.java
    功能:示範物件導向的基本觀念 
    作者:張凱慶
    時間:西元 2010 年 10 月 */


編譯後執行,結果如下



中英文術語對照
類別class
方法method
字串string






沒有留言: