「Java」equalsIgnoreCase()で大文字と小文字を区別しないサンプル
説明
public boolean equalsIgnoreCase(String anotherString)
大文字と小文字を区別せずに、このStringを別のStringと比較します。
使用例
package com.arkgame.study.cft;
public class EqualsIgnoreCaseDemo {
private static String flg = "true";
public static void main(String[] args) {
Boolean bA = Boolean.valueOf(true);
String strA = bA.toString();
Boolean bB = Boolean.valueOf("TRUE");
String strB = bB.toString();
String strC = "TRUE";
System.out.println("文字列A: " + strA + "文字列B: " + strB);
if (strA.equalsIgnoreCase(flg)) {
System.out.println("A001");
}
if (strB.equalsIgnoreCase(flg)) {
System.out.println("B002");
}
if (strC.equalsIgnoreCase(flg)) {
System.out.println("C003");
}
}
}
実行結果
文字列A: true文字列B: true
A001
B002
C003