0

I wrote an authenticator to see if an email ends with "@gmail.com". I don't really know why is this returns false. Could someone help me out why is it?

public static void main(String [] args){
    System.out.println(StringUtils.isValidGmail("a@gmail.com"));  // true
}


public static boolean isValidGmail(String email){
    if (email == null){
        return false;
    }
    int x = email.length() - 1;
    String gmail = email.substring(x-9, x+1);  // @gmail.com
    return gmail == "@gmail.com";
}
Dusernajder
  • 101
  • 1
  • 14

1 Answers1

2

you should replace return gmail == "@gmail.com"; by return gmail.equals("@gmail.com");

abdelmouheimen
  • 136
  • 2
  • 16