Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String object creation - double quotes, how? [duplicate]

Possible Duplicate:
Strings are objects in Java, so why don't we use 'new' to create them?

In Java, class objects are created like-

MyClass a=new MyClass();

then how String class objects are created like-

String a="Hello";

What does this "Hello" does to create new object?

like image 409
Naman Avatar asked Feb 18 '26 05:02

Naman


1 Answers

String a = "Hello" doesn't actually create a new object. Instead, when the compiler sees a string literal like "Hello", it adds the string to the string literal pool, from which it will be loaded later.

like image 193
Alexey Romanov Avatar answered Feb 20 '26 19:02

Alexey Romanov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!