java contains method with email breakdown

Recently I’ve been playing around with java and just had learned about if statements. Is there a particular reason why my if statement doesn’t work in this case? “


Java String contains() method checks whether a particular sequence of characters is part of a given string or not.

emailAddress.contains(“.edu , .org”) will only return true if the emailAddress contains the sequence “.edu , .org”.

You should use :

 emailAddress.contains(".edu") || emailAddress.contains(".org")

But what if a user has the following email address : “” ? Your if statement will also return true.

Good luck to improve this check 😁