🔥 Burn Fat Fast. Discover How! 💪

Facts about String #lang #jvm All string literals in Java prog | Java Tech News

Facts about String
#lang #jvm
All string literals in Java programs are represented with java.lang.String class.
• A String represents a string in the UTF-16 format.
• String concatenation operator is implemented by a compiler. For example, latest javac compiler will use java.lang.invoke.StringConcatFactory when sees + sign.
• charAt(int) is always O(1) even with random access
• Before JEP 254 strings with Latin-1 characters had unused 1 byte of storage, hence half of the space taken by a single char was unused.
• Compact Strings appeared with JEP 254 and brought coder field and backed char[] value store has been changed to byte[] value. It allows to reduce string memory footprint for Latin1 characters.
• You can't modify String class with Reflection API because it's protected by strong encapsulation of modules (provided by Java 9). The whole java.lang module was encapsulated by default.