Saved Bookmarks
| 1. |
Is there any difference in defining or creating a String by using String literal and by using the new() operator? |
|
Answer» Creating string using the new operator ensures that the String is created in the heap alone and not into the string pool. Whereas, creating string using literal ensures that the string is created in the string pool. String pool exists as part of the perm area in the heap. This ensures that the multiple Strings created using literal having same values are pointed to one object and prevents duplicate objects with the same value from being created. |
|