Here you can find the source of getHostName(String url)
public static String getHostName(String url) throws URISyntaxException
//package com.java2s; //License from project: Apache License import java.net.URI; import java.net.URISyntaxException; public class Main { public static String getHostName(String url) throws URISyntaxException { URI uri = new URI(url); String hostname = uri.getHost(); // to provide fault proof result, check if not null then return only hostname, without www. if (hostname != null) { hostname = hostname.startsWith("www.") ? hostname.substring(4) : hostname; hostname = uri.getScheme() + "://" + hostname; return hostname; }/*from ww w .j a v a 2 s .c om*/ return hostname; } }