Java Why is the string length twice 36 while it only contains 18 characters?

The next line st

only contains 18 characters, but when I print its length it shows 36 of it twice.

String st = "😖👱💢👤👥💬👣💭🐲🌍🌎🌏🌋🌌🌀🎍🎏🎇";
System.out.println(st.length());

      

Note: The string contains the characters that I am going to use in the chat application, the length may vary depending on the 16 bit and 8 bit characters, but I am vague.

+3


source to share


1 answer


According to JavaDocs: http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#length ()

Returns the length of this string. 
The length is equal to the number of Unicode code units in the string.

      



If you have Unicode characters that require multiple bytes, this length()

returns the total number of bytes, not the actual number of characters.

+7


source







All Articles