Java URL getHost() Method

The getHost() method of URL class returns the hostname of the URL. This method will return the IPv6 address enclosed in square brackets ('['and']').

Syntax

Parameter

NA

Returns

the hostname of this URL.

Example 1

Test it Now

Output:

The given url is : https://www.javatpoint.com/java-threadpoolexecutor
Host name in given url is : www.javatpoint.com

Example 2

Output:

Enter any url 
https://www.javatpoint.com/java-threadpoolexecutor
Host name in given url is : www.javatpoint.com

Example 3

Test it Now

Output:

Url1: https://www.javatpoint.com/URL-class
Url2: https://www.javatpoint.com/URL-class
Both url has Same host name  
Next TopicJava URL Class




Latest Courses