我不明白,爲什麼下面的代碼:Java字符無法正確識別
public Image getLetter(String letterToGet)
{
System.out.println("é" == "e");
System.out.println("Received: " + letterToGet);
if("\u00e9" == letterToGet.toLowerCase()); {
letterToGet = "SPECIALACCTAIGUESPECIAL";
}
if("\u00e8" == letterToGet.toLowerCase()) {
letterToGet = "SPECIALACCTGRAVESPECIAL";
}
System.out.println("searching for " + letterToGet + " in the hashmap");
return languageMap.get(letterToGet.toLowerCase());
}
可以返回輸出中
Traduction following ArrayList: [e, é, è]
Received: e
searching for SPECIALACCTAIGUESPECIAL in the hashmap
Received: é
searching for SPECIALACCTAIGUESPECIAL in the hashmap
Received: è
searching for SPECIALACCTAIGUESPECIAL in the hashmap
按照這樣的邏輯下,爲什麼這條線返回false? !
System.out.println("\u00e9" == "e");
可能的重複[如何比較Java中的字符串?](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – alfasin