Java URL getHost() Method

24 Mar 2025 | 1 min read

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

Output:

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

Example 2

Output:

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

Example 3

Output:

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