Efficient way to calculate byte length of a character, depending on the encoding
- by BalusC
What's the most efficient way to calculate the byte length of a character, taking the character encoding into account? In UTF-8 for example the characters have a variable byte length, so each character needs to be determined individually. As far now I've come up with this:
char c = getItSomehow();
String encoding = "UTF-8";
int length = new…