I have already read the following posts:
Neither of them mentions the search algorithm that is used by the JVM to search for String literals that have previously been created and exist in the so-called "String pool."
I have already read the following posts:
Neither of them mentions the search algorithm that is used by the JVM to search for String literals that have previously been created and exist in the so-called "String pool."
The implementation of String pool is done in native language i.e. c/c++ using Java Native Interface (JNI) and shared libraries
You can read how to do this here
As per me, string pool has been implemented using trie
data-structure
You can read about tries here
Trie
will take O(l) ,where l is length of the requested string, time to search the string pool.
UPD1: The String pool has been implemented as a hash-table and the memory allocation to the pool can be updated using -XX:StringTableSize=<value>
Though i feel use of trie
would have been better as trie
would have accommodated more number of strings in the same space to that of a hash-table