Here you can find the source of getHostname(String urlStr)
Parameter | Description |
---|---|
urlStr | URL |
public static String getHostname(String urlStr)
//package com.java2s; //License from project: Apache License import java.net.MalformedURLException; import java.net.URL; public class Main { /**/*from w ww .j a v a2s. c o m*/ * returns the hostname of the given URL * * @param urlStr * URL * @return hostname; null if the url is malformed */ public static String getHostname(String urlStr) { URL url; try { url = new URL(urlStr); String hostname = url.getHost(); return hostname; } catch (MalformedURLException e) { return null; } } }