search

Home  >  Q&A  >  body text

unicode - java的中文到底占几个字节?

查了一大堆,糊里糊涂的。现在知道以下几点:

迷茫迷茫2821 days ago892

reply all(3)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 14:57:26

    public static void main(String[] args) throws Exception{
        System.out.println("

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 14:57:26

    Usually we will set the encoding format to UTF-8. In Chinese, one Chinese character represents two characters in Java, 3 bytes

        public static void main(String[] args) {
            String str = "测试";
            System.out.println(str.getBytes().length);
        }

    Output: 6
    For the number of bytes occupied by different encoding formats, please refer to the blog:
    The number of bytes occupied by different encoding formats

    reply
    0
  • 黄舟

    黄舟2017-04-17 14:57:26

    Three UTF-8
    Two GBK

    reply
    0
  • Cancelreply