title: UTF-8 and UTF-16 in Java
body: <p>I really expect that the byte data below should show differently, but in fact, they are same, according to wiki <a href="http://en.wikipedia.org/wiki/UTF-8#Examples" rel="nofollow">http://en.wikipedia.org/wiki/UTF-8#Examples</a> , the encoding in byte look different, but why Java print them out as the same?</p>
  
  <pre><code>    String a = "€";
      byte[] utf16 = a.getBytes(); //Java default UTF-16
      byte[] utf8 = null;
  
      try {
          utf8 = a.getBytes("UTF-8");
      } catch (UnsupportedEncodingException e) {
          throw new RuntimeException(e);
      }
  
      for (int i = 0 ; i &lt; utf16.length ; i ++){
          System.out.println("utf16 = " + utf16[i]);
      }
  
      for (int i = 0 ; i &lt; utf8.length ; i ++){
          System.out.println("utf8 = " + utf8[i]);
      }
  </code></pre>