Here you can find the source of getHostName(String url)
public static String getHostName(String url) throws MalformedURLException
//package com.java2s; //License from project: Open Source License import java.net.MalformedURLException; public class Main { public static String getHostName(String url) throws MalformedURLException { if (url == null || url.length() == 0) return ""; url = url.toLowerCase();/*from ww w . j a v a2 s . c om*/ if (!url.startsWith("http://") && !url.startsWith("https://") && !url.startsWith("ftp://")) throw new MalformedURLException("Unknown schema!"); int doubleslash = url.indexOf("//"); doubleslash += 2; int end = url.length(); int idx = url.indexOf('/', doubleslash); if (idx > 0 && idx < end) end = idx; idx = url.indexOf(':', doubleslash); if (idx > 0 && idx < end) end = idx; idx = url.indexOf('&', doubleslash); if (idx > 0 && idx < end) end = idx; idx = url.indexOf('=', doubleslash); if (idx > 0 && idx < end) end = idx; idx = url.indexOf('#', doubleslash); if (idx > 0 && idx < end) end = idx; idx = url.indexOf('?', doubleslash); if (idx > 0 && idx < end) end = idx; return url.substring(doubleslash, end); } }