title: String length is getting wrong from two strings in java?
body: <p>Here i have two string name1 and name2 from that if letter is duplicated and least occurance that times has to delete.Eg: <code>String name1="raja"</code> and <code>name2="rani"</code> in that 'r' has to delete from both and 'a' occured 2 times in name1 and 1 time in name2 so only 'a' has to delete 1 time from name1 and name2 finally i need to get output as:'jani' and length is 4.But here length is coming three.This is my code.</p>
  
  <pre><code>String name1 = "raja";
  String name2 = "rani";
  for (int i = 0; i &lt; name1.length(); i++) {
      for (int j = 0; j &lt; name2.length(); j++) {
          if (name1.charAt(i) == name2.charAt(j)) {
              name1 = name1.replace(name1.charAt(i), '\0');
              name2 = name2.replace(name2.charAt(j), '\0');
          }
      }
  }
  String result = name1 + name2;
  String result = result.replaceAll("\0", "");
  int resultLength = result.length(); //need to get 4.
  </code></pre>
  
  <p>your help will be appreciated.</p>