How long is a piece of String (in Java 5.0)?

Up until Java SE 5.0 the length() method on a String used to give you the correct length of a String. Now that 5.0 uses additional chars to store character information, (ie a character may take more that 1 char of storage in memory), there is an aditional method, codePointCount(), that now accurately returns characters in a String.

This article on the Sun Java site explains in more detail.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.