title: Is it possible to add data to a string after adding "\0" (null)?
body: <p>I have a string that I am creating, and I need to add multiple "\0" (null) characters to the string. Between each null character, is other text data (Just ASCII alphanumeric characters).</p>
  
  <p>My problem is that in J2SE when you add the first null (\0), java then seems to determine that it's a string terminator, (similar to C++), and ignores all other data being appended. No error is raised, the trailing data is just ignored. I need to force the additional trailing data after a null in the string. I have to do this for a legacy database that I am supporting.</p>
  
  <p>I have tried to encode/decode the string in hoping that something like %00 would fool the interpretation of the string behaviour, but when I re-encode the string, Java sees the null character again, and removes all data after the first null.</p>
  
  <p>Update: Here is the relevant code snippet. Yes, I am trying to use <code>Strings</code>. I intend to try chars, but I still have to save it into the database as a string, so I suspect that I will end up with the same problem. </p>
  
  <p>Some background. I am receiving data via HTTP post that has "\n". I need to remove the newlines and replace them with "\0". The "<code>debug</code>" method is just a simple method that does <code>System.out.println</code>.</p>
  
  <pre><code>                String[] arrLines = sValue.split("\n");
                  for(int k=0;k&lt;arrLines.length;k++) {
                      if (0&lt;k) {
                          sNewValue += "\0";
                      }
                      sNewValue+= arrLines[k];
                      debug("New value =" + sNewValue);
                  }
  </code></pre>
  
  <p>sNewValue, a String, is committed to the database and needs to be done as a String. What I am observing when i display the current value of <code>sNewValue</code> after each iteration in the console is something like this:</p>
  
  <p>input is value1\nValue2\nValue3
  Output in the console is giving me from this code</p>
  
  <pre><code>value1
  value1
  value1
  </code></pre>
  
  <p>I am expecting </p>
  
  <pre><code>value1
  value1 value2
  value1 value2 value3 
  </code></pre>
  
  <p>with non-printable null between value1, value2 and value3 respectively. Note that the value actually getting saved back into the database is also just "value1". So, it's not just a console display problem. The data after \0 is getting ignored.</p>