Differences between Compact Strings and Compressed Strings in Java 9?



Compact Strings have introduced in Java 9 to replace Java 6's Compressed Strings. Its implementation uses byte[] array instead of char[] array and a new field coder has introduced to identify whether it is LATIN1 or UTF16 format while Compressed Strings have introduced in Java 6 that can be used byte[] array for one byte per character, and continued to use char[] array for two bytes per character, previously it can be turned on using -XX: + UseCompressedStrings.

Unlike Compressed Strings, Compact Strings do not require un-packing or re-packing. Hence Compact String gives better performance at runtime.

Compressed Strings are not enabled by default in Java 6, and need to be set explicitly using below command

XX:+UseCompressedStrings


Compact Strings are enabled by default in Java 9 by using the below command

+XX:-CompactStrings

Advertisements