Write a method, getEmailDomain, that is passed a String argument that is an email address and returns the domain name part. So if “mozart@salzberg.de” is passed, the method returns “salzberg.de”.

Write a method, getEmailDomain, that is passed a String argument that is an email address and returns the domain name part.  So if “mozart@salzberg.de” is passed, the method returns “salzberg.de”.

LANGUAGE: Java

CHALLENGE:

Write a method, getEmailDomain, that is passed a String argument that is an email address and returns the domain name part.
So if “mozart@salzberg.de” is passed, the method returns “salzberg.de”.
Assume that the argument will always be a correctly formatted email address.

SOLUTION:


String getEmailDomain(String str) {
    int ind = str.indexOf("@");
    return str.substring(ind + 1, str.length());
}


Add comment