可能重复:
如何比较 Java 中的字符串?
我有以下代码,但由于某种原因它不会更改字符串
accountClass 返回字符串“L”
String accountClass = accClass.substring(4, 5);
if (accountClass == "A") {
accountClass = "Staff - A";
} else if (accountClass == "B") {
accountClass = "Student - B";
} else if (accountClass == "H") {
accountClass = "Personal - H";
} else if (accountClass == "K") {
accountClass = "60 Plus - K";
} else if (accountClass == "L") {
accountClass = "Business - L";
} else if (accountClass == "P") {
accountClass = "Charity - P";
} else if (accountClass == "Q") {
accountClass = "AIB Subsidiary - Q";
} else if (accountClass == "X") {
accountClass = "Irish State Spons & Sub's - X";
} else if (accountClass == "Y") {
accountClass = "Other Companies & Orgs - Y";
} else if (accountClass == "Z") {
accountClass = "Impersonal & Gen. Ledger - Z";
}
我只是想知道它是否是 == 导致问题或其他原因?