Java URL sameFile 方法

2025年3月24日 | 阅读时间:2 分钟

URL 类的 sameFile() 方法会比较两个 URL,会忽略其片段(fragment)组件。如果两个 URL 在不考虑片段组件的情况下相等,则返回 true。

语法

参数

other - 要比较的 URL。

返回值

如果它们引用同一个远程对象,则返回 true;否则返回 false。

示例 1

输出

Url1 : https://tpointtech.cn/aptitude/quantitative
Url2 : https://tpointtech.cn/
 ***** compareing both url ***** 
 Both url has different file 

示例 2

输出

Enter any url 
https://tpointtech.cn/
File of Both url are equal : true

示例 3

输出

Both BaseUrl and relativeURL are equal? : false
下一个主题Java URL 类