Skip to content

Instantly share code, notes, and snippets.

@robd003
Created June 20, 2022 18:04
Show Gist options
  • Save robd003/295e56a13ece64c3e51c03e75ff086be to your computer and use it in GitHub Desktop.
Save robd003/295e56a13ece64c3e51c03e75ff086be to your computer and use it in GitHub Desktop.
Get domain from hostname
import com.google.common.net.InternetDomainName;
import java.net.URL;
public final class URLFunction {
private static String getDomain(String url_input) {
if (url_input.length() == 0) {
return url_input;
}
URL url = new URL(url_input);
String host = url.getHost();
InternetDomainName domain_name = InternetDomainName.from(host).topPrivateDomain();
return new String(domain_name);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment