title: Extract host name/domain name from URL string
body: <p>I have a URL like <code>http://hostname:port_no/control/login.jsp</code>.</p>
  
  <p>I have the above url stored in some String.Now, I need to extract <code>hostname</code> from the String.</p>
  
  <p>I am doing like this in my Java code</p>
  
  <pre><code>String domain = url.substring(url.indexOf('/') + 2, url.lastIndexOf(':'));
  </code></pre>
  
  <p>I want to know if there is any better way to do the same.</p>