I am sure you must be thrilled by the concept of the compact string feature we just learned about. Now let's look at the most common usage of string, which is concatenation. Have you ever wondered what really happens when we try to concatenate two strings? Let's explore. Take the following example:
public static String getMyAwesomeString(){ int javaVersion = 9; String myAwesomeString = "I love " + "Java " + javaVersion + " high performance book by Mayur Ramgir"; return myAwesomeString; }
In the preceding example, we are trying to concatenate a few strings with the int value. The compiler will then take your awesome strings, initialize a new StringBuilder instance, and then append all these individuals strings. ...