title: How to count String bytes properly?
body: <p>A <a href="/questions/tagged/java" class="post-tag" title="show questions tagged &#39;java&#39;" rel="tag">java</a> <a href="/questions/tagged/string" class="post-tag" title="show questions tagged &#39;string&#39;" rel="tag">string</a> containing special chars such as <code>ç</code> takes two bytes of size in each special char, but <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#length--" rel="nofollow noreferrer">String length method</a> or getting the length of it with the byte array returned from <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#getBytes--" rel="nofollow noreferrer">getBytes method</a> doesn't return special chars counted as two bytes.</p>
  
  <p>How can I count correctly the number of bytes in a String?</p>
  
  <p><strong>Example:</strong></p>
  
  <p>The word <code>endereço</code> should return me length 9 instead of 8.</p>