Co-Authored By:

Asked by: Itciar Izalzu
technology and computing programming languagesWhat is difference between string and new string?
Also know, what is the difference between string and new string in Java?
String strLiteral = "Java"; Bothexpression gives you String object, but there is subtledifference between them. When you create Stringobject using new() operator, it always create a newobject in heap memory. Otherwise it will create a new stringobject and put in string pool for futurere-use.
Similarly one may ask, what is the difference between a string and a string literal?
A String is a sequence of characters, aliteral is a raw, constant value used in your code.In Java for instance, you can have the following assignment:String s = “hello, world”; s is a stringvariable and the text “hello, world” is a StringLiteral.
String. A string is a data typeused in programming, such as an integer and floating point unit,but is used to represent text rather than numbers. It is comprisedof a set of characters that can also contain spaces and numbers.Option1 and Option2 may be variables containing integers,strings, or other data.