Skip to content

Instantly share code, notes, and snippets.

@peterkir
Last active April 18, 2016 05:22
Show Gist options
  • Save peterkir/87d02e8d90e95eea95b6 to your computer and use it in GitHub Desktop.
Save peterkir/87d02e8d90e95eea95b6 to your computer and use it in GitHub Desktop.
java.net.URL obstacles with URL.equals
package issue.java.net.url;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.LinkedHashSet;
import java.util.Set;
public class CanonicalURLs {
public static void main(String[] args) {
try {
Set<URL> set = new LinkedHashSet<>();
set.add(new URL("http://peterkir.github.io/"));
set.add(new URL("http://square.github.io/"));
set.add(new URL("http://Square.GitHub.io/"));
set.add(new URL("http://square.github.io:80/"));
set.add(new URL("http://google.github.io/"));
System.out.println(set); // prints only "http://peterkir.github.io/"
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
@peterkir
Copy link
Author

peterkir commented Jun 1, 2015

output is only the following (cause they are the same for Java)

[http://peterkir.github.io/]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment