What is the difference between creating String as new() and literal in java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

What is the difference between creating String as new() and literal in java?

2nd May 2017, 7:39 AM
Monarth Sarvaiya
2 Answers
+ 9
When you use = new String("string") you create a new String object and when you just use = "string" you refer to the same object. Read more about this in this article on StackOverflow: http://stackoverflow.com/questions/3297867/difference-between-string-object-and-string-literal
2nd May 2017, 8:16 AM
ChessMaster
ChessMaster - avatar
+ 8
thanks @ Serena so nicely explain
6th May 2017, 4:06 AM
minakshi singh
minakshi singh - avatar