java.net.URL equals() method is used to compare two URL objects for equality. The two URL objects are considered equal if they have the same protocol, host, port number, path, query string, and fragment identifier.
Code Examples:
Example 1:
URL url1 = new URL("https://www.example.com"); URL url2 = new URL("https://www.example.com");
boolean isEqual = url1.equals(url2); // true
In this example, we create two URL objects with the same URL and use the equals() method to compare them. Since they have the same URL, they are considered equal.
Example 2:
URL url1 = new URL("https://www.example.com"); URL url2 = new URL("https://www.example.org");
boolean isEqual = url1.equals(url2); // false
In this example, we create two URL objects with different URLs and use the equals() method to compare them. Since they have different URLs, they are not considered equal.
Package Library:
The java.net.URL class is part of the java.net package.
Java URL.equals - 30 examples found. These are the top rated real world Java examples of java.net.URL.equals extracted from open source projects. You can rate examples to help us improve the quality of examples.