I need to go through a large list of string url's and extract the domain name from them.
For example:
http://www.stackoverflow.com/questions would extract www.stackoverflow.com
I originally was using new URL(theUrlString).getHost()
but the URL object initialization adds a lot of time to the process and seems unneeded.
Is there a faster method to extract the host name that would be as reliable?
Thanks
Edit: My mistake, yes the www. would be included in domain name example above. Also, these urls may be http or https
If you want to handle
https
etc, I suggest you do something like this:Note that this is includes the
www
part (just asURL.getHost()
would do) which is actually part of the domain name.Edit Requested via comments
Here are two methods that might be helpful: