Languages
[Edit]
DE

Java - Domain-Name von der angegebenen URL abrufen

3 points
Created by:
Nikki
1659

In diesem Artikel wurde gezeigt, wie eine Domain von einer bestimmten URL in Java erhalten kann. 

Einfache Lösung:

import java.net.URI;
import java.net.URISyntaxException;

class DomainUtil {

    public static String getDomainName(String url) throws URISyntaxException {
        URI uri = new URI(url);
        String domain = uri.getHost();
        return domain.startsWith("www.") ? domain.substring(4) : domain;
    }
}

 

Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.