Mohamed Saligh
Mohamed Saligh

Reputation: 12349

what is the byte length for different character set in java?

I want to know the different byte length of character set provided by JVM. For example, ASCII, non-acsii char set, chinese characters and so on.

Any idea thanks :)

Upvotes: 1

Views: 603

Answers (2)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799180

ASCII, CP*, and ISO 8859-* are 1 byte. UCS-2 is 2 bytes. UTF-16 is 2 or 4 bytes. UTF-32 and UCS-4 are 4 bytes. Most others (UTF-8, GB2312, EUC-JP, ShiftJIS, etc.) are variable.

Upvotes: 0

AlexR
AlexR

Reputation: 115378

Call Charset.availableCharsets().values();, iterate over the list and print some predefined string into ByteArrayOutputStream. Then get bytes and see the array length.

Upvotes: 1

Related Questions