Java String Representation

String has four state members: offset, count (number of characters to be used), char[], hashcode.

substring() is designed to perform in O(1) by reusing the original char[]. This can lead to memory leak if the original String is big and the substring() is used to create a small String.  A work around is to pass the result of substring() to a new String(substring) constructor.

Starting Java 7 (1.7.0_06) Oracle got rid of offset & count fields, to fix the memory leak. This leads to substring performing in  O(n).

http://www.infoq.com/news/2013/12/Oracle-Tunes-Java-String

some musings…

What is the difference between operator and function?
* Operator acts on same types and returns the same type. Function can act on different types and give a new type.

What is the difference between tuples & list?
* Tuple is an immutable sequence of heterogenous items that are dealt as a coherent unit. List is mutable (to add/remove) sequnce of (most likey similar) items.