Efficient way to calculate byte length of a character, depending on the encoding

后端 未结 4 886
予麋鹿
予麋鹿 2021-02-06 00:48

What\'s the most efficient way to calculate the byte length of a character, taking the character encoding into account? The encoding would be only known during runtime. In UTF-8

4条回答
  •  庸人自扰
    2021-02-06 01:10

    Try Charset.forName("UTF-8").encode("string").limit(); Might be a bit more efficient, maybe not.

提交回复
热议问题