public static String urlNoFragString(URL url) {
        StringBuilder strForm = new StringBuilder();

        String protocol = url.getProtocol();
        if (protocol != null) {
            /* protocol is compared case-insensitive, so convert to lowercase */
            protocol = protocol.toLowerCase();
            strForm.append(protocol);
            strForm.append("://");
        }

        String host = url.getHost();
        if (host != null) {
            /* host is compared case-insensitive, so convert to lowercase */
            host = host.toLowerCase();
            strForm.append(host);

            int port = url.getPort();
            if (port == -1) {
                /* if no port is specificed then use the protocols
                 * default, if there is one */
                port = url.getDefaultPort();
            }
            if (port != -1) {
                strForm.append(":").append(port);
            }
        }

        String file = url.getFile();
        if (file != null) {
            strForm.append(file);
        }

        return strForm.toString();
    }
public static String urlNoFragString ( URL url ) { StringBuilder strForm = new StringBuilder ( ) ; String protocol = url . getProtocol ( ) ; if ( protocol != null ) { protocol = protocol . toLowerCase ( ) ; strForm . append ( protocol ) ; strForm . append ( "://" ) ; } String host = url . getHost ( ) ; if ( host != null ) { host = host . toLowerCase ( ) ; strForm . append ( host ) ; int port = url . getPort ( ) ; if ( port == - 1 ) { port = url . getDefaultPort ( ) ; } if ( port != - 1 ) { strForm . append ( ":" ) . append ( port ) ; } } String file = url . getFile ( ) ; if ( file != null ) { strForm . append ( file ) ; } return strForm . toString ( ) ; }
Returns a string form of the url suitable for use as a key in HashMap/Sets.

The string form should be behave in the same manner as the URL when
compared for equality in a HashMap/Set, except that no nameservice
lookup is done on the hostname (only string comparison), and the fragment
is not considered.

@see java.net.URLStreamHandler.sameFile(java.net.URL)