title: Java- How to verify if Thai characters are encoded correctly from UTF-8 to TIS620
body: <p>Get input string in UTF-8, I applied TIS620 encoding and created new string from it now how to retain the bytes? since UTF-8 represents Thai char in 3 bytes where as TIS620 in 1 byte. I've requirement where the backend system stores characters in string as 1 byte only so default UTF-8 breaks it.</p>
  
  <ol>
  <li>How to convert String character encoding from UTF-8 to TIS620?</li>
  <li>How to retain the byte size while passing it to backend system?</li>
  <li>If the string is reassigned to new String , Does character encoding is retained or it again gets converted to UTF-16 (Java default)?</li>
  <li>Is it possible in Java? Any lib/utility which can be integrated?</li>
  </ol>
  
  <p>I've tried below code and can check that post TIS620 the byte count matches the character count i.e.1 byte/char. But if encodedString gets new String assignment will it loose TIS620 format?</p>
  
  <p>(<a href="https://stackoverflow.com/questions/57521664/convert-string-with-encoding-utf-8-to-tis620-thai-encoding-in-java-what-are-th">Convert String with encoding UTF-8 to TIS620 (Thai encoding) in Java.What are the ways to do it and it there any data loss?</a>)</p>
  
  <pre><code>public String encode() {
          try {
  String input = " "ใบใบใบใบ"";
              byte [] encodedBytes= input.getBytes("TIS620");
              String encodedString = new String(encodedBytes,"TIS620");
              }catch (UnsupportedEncodingException e){
              //Encoding failed           
          }
      }
  </code></pre>
  
  <p>Expected result is, if I convert 5 Thai character from UTF-8 format to TIS620 the byte count should be converted and retained from 15 (UTF-8) to 5 (TIS620)?</p>