We create an object of the String class as shown in the following line of code:
String ab=new String();
Now, to create a hello string, you could simply pass an argument into the String class, as follows:
String ab=new String("hello");
The ab object can now perform all the string manipulations on this hello string.
Let's create another string, called b, which also equals to hello, as follows:
String a=new String("hello"); String b=new String("hello");
Here, though, there is already one hello string created with the a object, and when the Java compiler comes to the b object, it will still create one more duplicate hello string and assign it to b, because here we are explicitly forcing it to create an ...