Q1: What is difference between create String with the new keyword or without a new keyword?
- String s1 = new String("NIIT");
- String s2 = "NIIT";
the first statement will create the object of string type without searching anywhere.
the second statement will search String Constant Pool, the same content if found, it will reference the existing object without creating a new one, else will be created new object.
Q2: What is string constant pool? It is a special memory location where the strings had been created.