Java Get HostUrl Or Domain From a Given Link


Below method returns host-url or domain from a given link 

private String getDomainName(String url) {

	String domain = "";
	try {
		URL uri = new URL(url);
		domain = uri.getHost();
	} catch (MalformedURLException e) {
		e.printStackTrace();
	}

	return domain;
}


getDomainName("https://www.tutorialsbuzz.com/2018/09/android-hello-world-example.html");

No comments:

Post a Comment