Compare two urls in java
package com.w3spoint;
import java.net.MalformedURLException;
import java.net.URL;
public class URLTest {
public static void main(String args[]){
try {
URL url1 = new URL("https://www.w3schools.blog");
URL url2 = new URL("https://www.java.com");
if(url1.equals(url2)){
System.out.println("URLs are equal");
} else {
System.out.println("URLs are not equal");
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
} |
package com.w3spoint; import java.net.MalformedURLException;
import java.net.URL; public class URLTest {
public static void main(String args[]){
try {
URL url1 = new URL("https://www.w3schools.blog");
URL url2 = new URL("https://www.java.com");
if(url1.equals(url2)){
System.out.println("URLs are equal");
} else {
System.out.println("URLs are not equal");
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}
Output