Java URL to Host Name getHost(String url)

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

Description

Returns the lowercased hostname for the url or null if the url is not well formed.

License

LGPL

Parameter

Parameter Description
url The url to check.

Return

String The hostname for the url.

Declaration

public static String getHost(String url) 

Method Source Code

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

import java.net.MalformedURLException;
import java.net.URL;

public class Main {
    /**//from w w w  . j  a  v a 2  s  . c o  m
     * Returns the lowercased hostname for the url or null if the url is not well
     * formed.
     * 
     * @param url The url to check.
     * @return String The hostname for the url.
     */
    public static String getHost(String url) {
        try {
            return new URL(url).getHost().toLowerCase();
        } catch (MalformedURLException e) {
            return null;
        }
    }
}

Related

  1. getHost(String url)
  2. getHost(String url)
  3. getHost(String url)
  4. getHost(String url)
  5. getHost(String urlString)