Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 ALL


  String.length() vs String.getBytes().length in Java

In Java, String.length() is to return the number of characters in the string, while String.getBytes().length is to return the number of bytes to represent the string with the specified encoding. By default, the encoding will be the value of system property file.encoding, the encoding name can be set manually as well by calling System.setProperty("file.encoding", "XXX"). For example, UTF-8, Cp1252. In many cases, String.length() will return the same value as String.getBytes().length, but in some cases it's not the same.String.length() is the number of UTF-16 code units needed to represent the s...

111,024 0       JAVA STRING ENCODING SAMPLE UTF8