title: Converting array string to string and back in Java
body: <p>I have an array String[] in Java, and must first encode/convert it into a String and then further in the code covert it back to the String[] array. The thing is that I can have any character in a string in String[] array so I must be very careful when encoding. And all the information necessary to decode it must be in the final string. I can not return a string and some other information in an extra variable.</p>
  
  <p>My algorithm I have devised so far is to:</p>
  
  <ol>
  <li><p>Append all the strings next to each other, for example like this:
  String[] a = {"lala", "exe", "a"}
  into
  String b = "lalaexea"</p></li>
  <li><p>Append at the end of the string the lengths of all the strings from String[], separated from the main text by $ sign and then each length separated by a comma, so:</p></li>
  </ol>
  
  <p>b = "lalaexea$4,3,1"</p>
  
  <p>Then when converting it back, I would first read the lengths from behind and then based on them, the real strings.</p>
  
  <p>But maybe there is an easier way?</p>
  
  <p>Cheers!</p>