What is the difference between these two ways of instantiating a String in Java?
String x = "y";
String x = new String("y");
What is the difference between these two ways of instantiating a String in Java?
String x = "y";
String x = new String("y");
Basic difference is that the first example will stay in the string pool and the second in the object memory.
Furthermore using String x = new String("y");
is slower than the other method.
Check out this link to understand the string pool String performance in Java