title: Recursive removal of characters in Java
body: <p>As an exercise, the code block below intends to recursively go through a string and remove all the of the "x" characters. It does that, but I would like to keep track of the newStr without passing it as a parameter in the method. Is there anyway to move it into the method body?</p>
  
  <p>Thanks!</p>
  
  <pre><code>public static String deathToX(String str, String newStr) {  
      //look for x char
      if(str.substring(0, 1).equals("x")) {
          //do nothing
      } else {
          //add non-x char to newStr
          newStr += str.charAt(0);
      }
  
      if(str.length() == 1) {
          return newStr;
      }
  
      return deathToX(str.substring(1), newStr);
  }
  
  public static void main(String[] args) {
      System.out.println("Return: " + deathToX("xnoxmore", ""));
  }
  </code></pre>