Java 9 Compact Strings Example

Yatin B.Yatin B.
1 min read

Date: 2017-07-04

Java 9's JEP 254 introduces "Compact Strings," optimizing string memory usage. Previously, Java strings used 16 bits per character, even for characters representable in 8 bits. Compact Strings attempt to store strings using only 8 bits per character if possible (LATIN-1), switching to 16 bits (UTF-16) if necessary. This internal change improves performance and reduces memory footprint, particularly for applications with many strings containing primarily LATIN-1 characters. While there are some minor performance trade-offs, the overall impact is positive, resulting in reduced memory consumption and faster garbage collection. The feature is enabled by default but can be disabled with -XX:-CompactStrings.

Read more: https://examples.javacodegeeks.com/core-java/java-9-compact-strings-example/

0
Subscribe to my newsletter

Read articles from Yatin B. directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Yatin B.
Yatin B.