title: In java, what's the best way to read a url and split it into its parts?
body: <p>Firstly, I am aware that there are other posts similar, but since mine is using a URL and I am not always sure what my delimiter will be, I feel that I am alright posting my question. My assignment is to make a crude web browser. I have a textField that a user enters the desired URL into. I then have obviously have to navigate to that webpage. Here is an example from my teacher of what my code would look kinda like. This is the code i'm suposed to be sending to my socket. Sample url: <a href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol" rel="noreferrer">http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol</a></p>
  
  <pre><code> GET /wiki/Hypertext_Transfer_Protocol HTTP/1.1\n
  Host: en.wikipedia.org\n
  \n
  </code></pre>
  
  <p>So my question is this: I am going to read in the url as just one complete string, so how do I extract just the "en.wikipedia.org" part and just the extension? I tried this as a test:</p>
  
  <pre><code> String url = "http://en.wikipedia.org/wiki/Hypertext Transfer Protocol";
      String done = " ";
      String[] hope = url.split(".org");
  
      for ( int i = 0; i &lt; hope.length; i++)
      {
          done = done + hope[i];
      }
      System.out.println(done);
  </code></pre>
  
  <p>This just prints out the URL without the ".org" in it. I think i'm on the right track. I am just not sure. Also, I know that websites can have different endings (.org, .com, .edu, etc) so I am assuming i'll have to have a few if statements that compenstate for the possible different endings. Basically, how do I get the url into the two parts that I need?</p>