Home > Enterprise >  java contains method with email breakdown
java contains method with email breakdown

Time:10-23

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? ``

CodePudding user response:

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 : "[email protected]" ? Your if statement will also return true.

Good luck to improve this check

  • Related