Ask Your Question
2

What is the distinction between the lengths returned by String.length() and String.getBytes().length?

asked 2023-01-06 11:00:00 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-02-19 09:00:00 +0000

plato gravatar image

String.length() returns the number of characters in the String while String.getBytes().length returns the number of bytes used to represent the characters in the String using the specified character encoding. The length returned by String.getBytes().length can be different for different character encodings. For example, a String containing only ASCII characters will have the same length for both String.length() and String.getBytes("UTF-8").length, but may have a different length for String.getBytes("ISO-8859-1").length.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-01-06 11:00:00 +0000

Seen: 1 times

Last updated: Feb 19 '22