title: Replacing characters at a certain index from string, using recursion
body: <p>Hi im trying to create a method to remove the spaces from a word recursively. Ive done this so far, and im really not sure why its not working.</p>
  
  <pre><code>public static String compact (String line)
  {
  
      for (int x = 0 ; x &lt; line.length () ; x++)
      {
          if (line.charAt (x) == ' ')
          {
              String newLine = line.substring (0, x) + line.substring (x);
              return compact (newLine);
          }
          else
              break;
      }
      return line;
  }
  </code></pre>
  
  <p>This just returns the original string without removing any spaces.
  Can someone please tell me what im doing wrong, thanks.</p>