Java URL getHost() 方法

2025年3月24日 | 1 分钟阅读

URL 类的 getHost() 方法返回 URL 的主机名。此方法将返回用方括号 ('['和']') 括起来的 IPv6 地址。

语法

参数

不适用

返回值

此 URL 的主机名。

示例 1

输出

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

示例 2

输出

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

示例 3

输出

Url1: https://tpointtech.cn/URL-class
Url2: https://tpointtech.cn/URL-class
Both url has Same host name  
下一个主题Java URL 类