June 2018
Intermediate to advanced
316 pages
6h 34m
English
If you create a string using quotes, the newly created object is automatically placed in a String pool. The String pool is a special section in memory that stores a set of unique strings. Whenever you create a new instance of the String class using quotes, the virtual machine looks for an equal string in the String pool and returns the found instance (if an instance exists). If an equal object isn't found, then a new instance is placed in the String pool before returning a reference to it. If you receive a new string from the outside, as in the following example, you can use the intern() method to push a string value to the String pool:
val firstLine: String get() = File("input.txt") .inputStream() .bufferedReader() .use ...
Read now
Unlock full access