Possible Duplicate:
Java String.equals versus ==
I have a string called DomainType
which usually holds values like "edu,com,org..etc" from a url. I used an if else statement to help check the data type and output a JOptionPane
. For some reason whenever you type any domain type, It gives you the last option.
Here is a Snippet from the code I wrote:
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.");
}
so the DomainType
gives me edu or com no problem but i think it's my if statement I'm not doing right.