On this Oracle page Java HotSpot VM Options, it lists -XX:+UseCompressedStrings
as being available and on by default. However in Java 6 update 29, it is off by
Just to add, for those interested...
The java.lang.CharSequence interface (which java.lang.String
implements), allows more compact representations of Strings than UTF-16.
Apps which manipulate a lot of strings, should probably be written to accept CharSequence
, such that they would work with java.lang.String
, or more compact representations.
8-bit (UTF-8), or even 5, 6, or 7-bit encoded, or even compressed strings can be represented as CharSequence
.
CharSequence
s can also be a lot more efficient to manipulate - subsequences can be defined as views (pointers) onto the original content for example, instead of copying.
For example in concurrent-trees, a suffix tree of ten of Shakespeare's plays, requires 2GB of RAM using CharSequence
-based nodes, and would require 249GB of RAM if using char[] or String-based nodes.