What is the difference between

String s="abc" and

String s=new String("abc");

The first one basically reads as follows :
"Create a string object called S where S refers to the statically defined string object "abc".

The second one reads as follows :
"Create a string object called S, where S points to a new dynamically allocated string object with the value 'abc' "

Use the first one when you can.

The first one basically reads as follows :
"Create a string object called S where S refers to the statically defined string object "abc".

The second one reads as follows :
"Create a string object called S, where S points to a new dynamically allocated string object with the value 'abc' "

I'm afraid that kind of simplicity won't work when explaining the concept of String pools in Java.

What is the difference between

String s="abc" and

String s=new String("abc");

Read this thoroughly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.