<p>The <code>equals()</code> method of the URL class in the Java class library makes a DNS request to get the IP for the hostname, to check the two IP's for equality. This happens even for URLs that are created from the same <code>String</code>. Is there a way to avoid this internet access?</p>

Don't use URL.equals. As the documentation says,
Note: The defined behavior for
```
equals
```
is known to be inconsistent with virtual hosting in HTTP.