
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
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
- Related Articles
- What are Compact Strings in Java 9?
- Comparing Strings and Portions of Strings in Java
- Printing Integer between Strings in Java
- Differences between Java 8 and Java 9?
- Differences in two strings in JavaScript
- Differences between CompletableFuture and Future in Java 9?
- Differences between takewhile() and dropWhile() methods in Java 9?
- Differences between orTimeout() and completeOnTimeOut() methods in Java 9?
- Differences between Optional.ifPresentOrElse() and Optional.or() methods in Java 9?
- Differences between Jdeps and Jdeprscan tools in Java 9?
- Manipulating Strings in Java.
- Join Strings in Java
- concat(), replace(), and trim() Strings in Java.
- Concatenation of Strings in Java
- Concatenate Multiple Strings in Java.
