title: How do I format my String to include the needed white space?
body: <p>I have a String that I want to format in Java. Here is my code:</p>
  
  <hr/>
  
  <pre><code>import java.util.*;
  public class Test{
  
  public static void main(String[] args){
    String a = "John       College of NY      NY  10286";
    a = removeSpaces(a);
    System.out.println(a);  
  }
  
  public static String removeSpaces(String s) {
    StringTokenizer st = new StringTokenizer(s," ",false);
    String t = "";
    while(st.hasMoreElements()){
       t =  t + ";" + st.nextElement();
    }
    return t;
  }
  </code></pre>
  
  <p><hr/>
  <BR>
  When I run my code I get this back: (don't mind the semicolon in the front)  </p>
  
  <hr> 
  
  <pre><code>;John;College;of;NY;NY;10286
  </code></pre>
  
  <p><hr>
  <BR>
  The output text should be separated by a semicolon in three parts like so, and it should preserve the 1 or 2 white spaces in the last two: 
  <BR></p>
  
  <hr>
  
  <pre><code>;John;College of NY;NY  10286;
  </code></pre>
  
  <p><hr>
  I am not sure how to keep the the white space between "College" and "of" &amp; "of" and "NY". Or the two white spaces between "NY" and "10286". How can I format the line? </p>