Link to home
Start Free TrialLog in
Avatar of aturetsky
aturetsky

asked on

getting host from URL string

I have a url string and I'd like to get the host out of it.

Now, I know I can just do:

URL url = new URL("http:///whatever.com/whatever?whatever=whatever");
String host = url.getHost();

But must I really instatiate a URL every time?  Is there some kind of a static utility class that would do this without the need to do "new URL" ?  For the purposes of this question, assume that I don't want to be manually parsing the string using a regex or a substring.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aturetsky
aturetsky

ASKER

Thanks to all you.  I must admit it's rare to see this kind of consensus here - so this must be the way to go, then.
:-)