Java URL to Host Name getHostName(String url)

Here you can find the source of getHostName(String url)

Description

Gets a host from given URL

License

Apache License

Parameter

Parameter Description
url Given URL

Exception

Parameter Description
URISyntaxException an exception

Return

a host name

Declaration

public static String getHostName(String url) throws URISyntaxException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    /**//from w  w w .  j ava2 s  .  co m
     * Gets a host from given URL
     * @param url Given URL
     * @return a host name
     * @throws URISyntaxException
     */
    public static String getHostName(String url) throws URISyntaxException {
        URI uri = new URI(url);
        return uri.getHost();
    }
}

Related

  1. getHostFromURL(final String urlSpec)
  2. getHostname(String completeUrl)
  3. getHostName(String url)
  4. getHostName(String url)
  5. getHostName(String url)
  6. getHostname(String urlStr)
  7. getHostSegments(URL url)