| Advantages of the String implementation in JAVA | | | | 2. 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 includes | | | | underlying sequence of characters. Instead, a substring |
| applying the concatenation operator and converting | | | | can use the same char array as the original string and |
| other literals to strings. So hi7 and (hi+7) both get | | | | simply refer to a different start point and endpoint in |
| resolved at compile time to the same string, and are | | | | the char array. This means that substring operations |
| identical objects in the class string pool. Compilers differ | | | | are efficient, being both fast and conserving of |
| in their ability to achieve this resolution. You can always | | | | memory; the extra object is just a wrapper on the |
| check your compiler (e.g., by decompiling some | | | | same underlying char array with different pointers into |
| statements involving concatenation) and change it if | | | | that array. |
| needed. | | | | |