troubleshooting Question

getting host from URL string

Avatar of aturetsky
aturetsky asked on
Java
5 Comments3 Solutions301 ViewsLast Modified:
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.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 3 Answers and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros