濡備綍閲嶅啓equalsignorecase鏂规硶
瑕侀噸鍐檈qualsIgnoreCase鏂规硶锛岄鍏堥渶瑕佸垱寤轰竴涓柊鐨勬柟娉曪紝鑰屼笉鏄噸鍐橲tring绫讳腑鐨別qualsIgnoreCase鏂规硶銆備互涓嬫槸涓€涓ず渚嬶細
public class CustomString {
private String value;
public CustomString(String value) {
this.value = value;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof CustomString) {
CustomString other = (CustomString) obj;
return this.value.equalsIgnoreCase(other.value);
}
return false;
}
public static void main(String[] args) {
CustomString str1 = new CustomString("Hello");
CustomString str2 = new CustomString("hello");
System.out.println(str1.equals(str2)); // Output: true
}
}
鍦ㄤ笂闈㈢殑渚嬪瓙涓紝鎴戜滑鍒涘缓浜嗕竴涓嚜瀹氫箟鐨凜ustomString绫伙紝骞堕噸鍐欎簡equals鏂规硶锛屼互渚垮拷鐣ュぇ灏忓啓姣旇緝涓や釜CustomString瀵硅薄鐨勫€笺€傚湪main鏂规硶涓紝鎴戜滑鍒涘缓浜嗕袱涓狢ustomString瀵硅薄锛屽苟璋冪敤equals鏂规硶杩涜姣旇緝銆傛渶缁堣緭鍑虹粨鏋滀负true锛岃〃绀轰袱涓璞$殑鍊煎湪蹇界暐澶у皬鍐欑殑鎯呭喌涓嬫槸鐩哥瓑鐨勩€?/p>