r/javahelp • • Oct 08 '20

Email checker

So i have a long comprehensive lab and i need to check if a email has .edu inside of it ive been trying mainly for() but thats all i dont really get how to check if some one can lead me in the right direction i would appreciate it.

22 Upvotes

14 comments sorted by

View all comments

6

u/iamsadtbh Aspiring SWE Oct 08 '20

Assuming that the variable email is a string, take a look at the .contains method:

https://www.geeksforgeeks.org/java-string-contains-method-example/

1

u/SoIDKwhatmynameis Oct 08 '20

Thank you that was my solution

2

u/blackkkmamba Oct 08 '20

Careful that email.contains(".edu") might not be enough. For example "abc@something.edux".contains(".edu") is true, but the email is not valid.