Advantage and disadvantages of String Implementation in JAVA

Advantages of the String implementation in JAVA2. Because String objects are immutable, a substring
1. Compilation creates unique strings. At compile time,operation doesn’t need to copy the entire
strings are resolved as far as possible. This includesunderlying sequence of characters. Instead, a substring
applying the concatenation operator and convertingcan use the same char array as the original string and
other literals to strings. So hi7 and (hi+7) both getsimply refer to a different start point and endpoint in
resolved at compile time to the same string, and arethe char array. This means that substring operations
identical objects in the class string pool. Compilers differare efficient, being both fast and conserving of
in their ability to achieve this resolution. You can alwaysmemory; the extra object is just a wrapper on the
check your compiler (e.g., by decompiling somesame underlying char array with different pointers into
statements involving concatenation) and change it ifthat array.
needed.