@SuppressWarnings("StringSplitter")
    public static List<String> extractImportantUrlData(String text) throws MalformedURLException {
        final List<String> importantParts = new ArrayList<>();
        final URL url = new URL(text);
        final String[] domain = url.getHost().split("\\.");
        //add the domain except www and the tld.
        for (int i = 0; i < domain.length - 1; i++) {
            final String sub = domain[i];
            if (Arrays.binarySearch(IGNORE_LIST, sub.toLowerCase()) < 0) {
                importantParts.add(sub);
            }
        }
        final String document = url.getPath();
        final String[] pathParts = document.split("[\\//]");
        for (int i = 0; i < pathParts.length - 1; i++) {
            if (!pathParts[i].isEmpty()) {
                importantParts.add(pathParts[i]);
            }
        }
        if (pathParts.length > 0 && !pathParts[pathParts.length - 1].isEmpty()) {
            final String tmp = pathParts[pathParts.length - 1];
            final int pos = tmp.lastIndexOf('.');
            if (pos > 1) {
                importantParts.add(tmp.substring(0, pos));
            } else if (pos == 0 && tmp.length() > 1) {
                importantParts.add(tmp.substring(1));
            } else {
                importantParts.add(tmp);
            }
        }
        return importantParts;
    }
@ SuppressWarnings ( "StringSplitter" ) public static List < String > extractImportantUrlData ( String text ) throws MalformedURLException { final List < String > importantParts = new ArrayList < > ( ) ; final URL url = new URL ( text ) ; final String [ ] domain = url . getHost ( ) . split ( "\\." ) ; for ( int i = 0 ; i < domain . length - 1 ; i ++ ) { final String sub = domain [ i ] ; if ( Arrays . binarySearch ( IGNORE_LIST , sub . toLowerCase ( ) ) < 0 ) { importantParts . add ( sub ) ; } } final String document = url . getPath ( ) ; final String [ ] pathParts = document . split ( "[\\//]" ) ; for ( int i = 0 ; i < pathParts . length - 1 ; i ++ ) { if ( ! pathParts [ i ] . isEmpty ( ) ) { importantParts . add ( pathParts [ i ] ) ; } } if ( pathParts . length > 0 && ! pathParts [ pathParts . length - 1 ] . isEmpty ( ) ) { final String tmp = pathParts [ pathParts . length - 1 ] ; final int pos = tmp . lastIndexOf ( '.' ) ; if ( pos > 1 ) { importantParts . add ( tmp . substring ( 0 , pos ) ) ; } else if ( pos == 0 && tmp . length ( ) > 1 ) { importantParts . add ( tmp . substring ( 1 ) ) ; } else { importantParts . add ( tmp ) ; } } return importantParts ; }
<p>
Takes a URL, in String format, and adds the important parts of the URL to
a list of strings.</p>
<p>
Example, given the following input:</p>
<code>"https://www.somedomain.com/path1/path2/file.php?id=439"</code>
<p>
The function would return:</p>
<code>{"some.domain", "path1", "path2", "file"}</code>

@param text a URL
@return importantParts a list of the important parts of the URL
@throws MalformedURLException thrown if the URL is malformed