Proper way to check for URL equality

后端 未结 3 1467
無奈伤痛
無奈伤痛 2021-02-02 11:53

I have the following scenario:

URL u1 = new URL(\"http://www.yahoo.com/\");
URL u2 = new URL(\"http://www.yahoo.com\");

if (u1.equals(u2)) {
    System.out.prin         


        
3条回答
  •  醉话见心
    2021-02-02 12:21

    You can always compare relative URLs with Path.equals-method

    ex.

    Paths.get("/user/login").equals(Paths.get("/user/login/")))
    

    produce true

    You can also use startsWith/endsWith-methods

提交回复
热议问题