Splitting on a period and selecting the first or second element (whichever is not "www") would work:
URL url = new URL("http://www.host.ext.ext");
String host = url.getHost(); // host = "www.host.ext.ext"
String splitHost = host.split("\\.") // splitHost = { "www", "host", "ext", "ext" }
host = splitHost[0].equals("www") ? splitHost[1] : splitHost[0]; // host = "host"
If there is anything more than http://www.
before it, and the extension is potentially more than two "extensions" (.co.uk
for instance), then there is no easy way to get just the part you want. As far as I know, you would have to try iterating over a list of extensions and return the part immediately before the longest matching extension.