943,985 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 454
  • Java RSS
Oct 13th, 2009
0

boolean return problem

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

Java Syntax (Toggle Plain Text)
  1. private boolean check(String mail, int N){
  2. // mail = The mail
  3. // N = The sum of the characters before the @ and including it him
  4. if(mail.substring(N) == "hotmail.com" || mail.substring(N) == "live.com" ||
  5. mail.substring(N) == "msn.com" || mail.substring(N) == "yahoo.com" ||
  6. mail.substring(N) == "gmail.com"){
  7. return true;
  8. } else {
  9. return false;
  10. }
  11. }

...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.
Similar Threads
Reputation Points: 17
Solved Threads: 5
Junior Poster
Krstevski is offline Offline
110 posts
since May 2009
Oct 13th, 2009
0
Re: boolean return problem
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).
Reputation Points: 69
Solved Threads: 48
Posting Whiz in Training
nmaillet is offline Offline
203 posts
since Aug 2008
Oct 13th, 2009
0
Re: boolean return problem
The problem is solved.

Thanks nmaillet.
Reputation Points: 17
Solved Threads: 5
Junior Poster
Krstevski is offline Offline
110 posts
since May 2009
Oct 14th, 2009
0
Re: boolean return problem
ps
Java Syntax (Toggle Plain Text)
  1. if (some boolean expression) {
  2. return true;
  3. } else {
  4. return false;
  5. }
is just the long way to say
Java Syntax (Toggle Plain Text)
  1. return (some boolean expression);
Featured Poster
Reputation Points: 1924
Solved Threads: 952
Posting Expert
JamesCherrill is offline Offline
5,789 posts
since Apr 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: help me if you want to, i really dont care
Next Thread in Java Forum Timeline: JOptioPane-Determining the output integer





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC