boolean return problem

Thread Solved

Join Date: May 2009
Posts: 29
Reputation: Krstevski is an unknown quantity at this point 
Solved Threads: 0
Krstevski's Avatar
Krstevski Krstevski is offline Offline
Light Poster

boolean return problem

 
0
  #1
Oct 13th, 2009
Hey guys, I have one stupid problem with the return value of one function... this is my code:

  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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 83
Reputation: nmaillet is an unknown quantity at this point 
Solved Threads: 18
nmaillet nmaillet is offline Offline
Junior Poster in Training
 
0
  #2
Oct 13th, 2009
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).
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 29
Reputation: Krstevski is an unknown quantity at this point 
Solved Threads: 0
Krstevski's Avatar
Krstevski Krstevski is offline Offline
Light Poster
 
0
  #3
Oct 13th, 2009
The problem is solved.

Thanks nmaillet.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 972
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 146
JamesCherrill JamesCherrill is offline Offline
Posting Shark
 
0
  #4
Oct 14th, 2009
ps
  1. if (some boolean expression) {
  2. return true;
  3. } else {
  4. return false;
  5. }
is just the long way to say
  1. return (some boolean expression);
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC