How to compare two URLs in java?

前端 未结 4 1241
逝去的感伤
逝去的感伤 2020-12-03 21:56

Here\'s a simple problem - given two urls, is there some built-in method, or an Apache library that decides whether they are (logically) equal?

For example, these tw

4条回答
  •  一生所求
    2020-12-03 22:10

    While URI.equals() (as well as the problematic URL.equals()) does not return true for these specific examples, I think it's the only case where equivalence can be assumed (because there is no empty path in the HTTP protocol).

    The URIs http://stackoverflow.com/foo and http://stackoverflow.com/foo/ can not be assumed to be equivalent.

    Maybe you can use URI.equals() wrapped in a utility method that handles this specific case explicitly.

提交回复
热议问题