0

Hey guys, I have one stupid problem with the return value of one function... this is my code:

private boolean check(String mail, int N){
                               // mail = The mail
                               // N = The sum of the characters before the @ and including it him
		if(mail.substring(N) == "hotmail.com" || mail.substring(N) == "live.com" ||
				mail.substring(N) == "msn.com" || mail.substring(N) == "yahoo.com" ||
				mail.substring(N) == "gmail.com"){
			return true;
		} else {
			return false;
		}
	}

...and if the mail is daniweb@hotmail.com then mail.substring(N) will be hotmail.com but the return value will be false.

Where is my mistake?

Thanks.

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by JamesCherrill
0

The == operator does not compare the characters of the string. It checks to see if they are referring to the same object. Use the mail.substring(N).equals("hotmail.com") method to compare the characters (or equalsIgnoreCase() I think).

0

ps

if (some boolean expression) {
   return true;
} else {
   return false;
}

is just the long way to say

return  (some boolean expression);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.