<分区>
Possible Duplicate:
Java String.equals versus ==
我有一个名为 DomainType
的字符串,它通常包含来自 url 的值,例如“edu,com,org..etc”。我使用 if else 语句来帮助检查数据类型并输出 JOptionPane
。出于某种原因,每当您键入任何域类型时,它都会为您提供最后一个选项。
这是我编写的代码片段:
DomainType = URL.substring(URLlength - 3, URLlength);
if (DomainType == "gov") {
JOptionPane.showMessageDialog(null, "This is a Government web address.");
}
else if (DomainType == "edu") {
JOptionPane.showMessageDialog(null, "This is a University web address.");
}
else if (DomainType == "com") {
JOptionPane.showMessageDialog(null, "This is a Business web address.");
}
else if (DomainType == "org") {
JOptionPane.showMessageDialog(null, "This is a Organization web address");
}
else {
JOptionPane.showMessageDialog(null, "This is an unknown web address type.");
}
所以 DomainType
给了我 edu 或 com 没有问题,但我认为这是我的 if 语句我做的不对。