title: Is an instance of a Java string always valid UTF-16?
body: <p>For any given Java String <code>s</code>, I would like to know if the array of characters represented by <code>s</code> is <strong>guaranteed</strong> to be a valid UTF-16 string, e.g.:</p>
  
  <pre><code>final char[] ch = new char[s.length()];
  for (int i = 0; i &lt; ch.length; ++i) {
      ch[i] = s.charAt(i);
  }
  // Is ch guaranteed to be a valid UTF-16 encoded string?
  </code></pre>
  
  <p>If not, what are some simple Java-language test cases that produce invalid UTF-16?</p>
  
  <p><strong>EDIT</strong>: Somebody has flagged the question as a possible duplicate of [<a href="https://stackoverflow.com/questions/31613779/is-a-java-char-array-always-a-valid-utf-16-big-endian-encoding]">Is a Java char array always a valid UTF-16 (Big Endian) encoding?</a> All I can say is, there's a difference between a <code>String</code> and a <code>char[]</code> and a reason why the former might, at least theoretically, have guarantees as to its contents that the latter does not. I'm not asking a question about arrays, I'm asking a question about <code>String</code>s.</p>