equalsIgnoreCase() 方法用于將字符串與指定的對象比較,不考慮大小寫。
語法
public boolean equalsIgnoreCase(String anotherString)
參數(shù):anObject -- 與字符串進(jìn)行比較的對象。
返回值:如果給定對象與字符串相等,則返回 true;否則返回 false。
實例
public class Test { public static void main(String args[]) { String Str1 = new String("runoob"); String Str2 = Str1; String Str3 = new String("runoob"); String Str4 = new String("RUNOOB"); boolean retVal; retVal = Str1.equals( Str2 ); System.out.println("返回值 = " + retVal ); retVal = Str3.equals( Str4); System.out.println("返回值 = " + retVal ); retVal = Str1.equalsIgnoreCase( Str4 ); System.out.println("返回值 = " + retVal ); } }
以上程序執(zhí)行結(jié)果為:
返回值 = true 返回值 = false 返回值 = true
以上就是java比較字符不區(qū)分大小寫的方法的詳細(xì)內(nèi)容,更多請關(guān)注創(chuàng)新互聯(lián)其它相關(guān)文章!