+ 1

What is difference between string and string literal?

20th Jun 2018, 11:42 AM
Suraj Prashar
Suraj Prashar - avatar
2 Answers
+ 4
A "string literal" is a sequence of characters from the source character set enclosed in double quotation marks (" "). String literals are used to represent a sequence of characters which, taken together, form a null-terminated string. https://stackoverflow.com/questions/3297867/difference-between-string-object-and-string-literal https://www.sololearn.com/discuss/357807/?ref=app
20th Jun 2018, 1:13 PM
Scooby
Scooby - avatar
0
n java, String can be initialized as Literal or Object. String Literal String a = “ABC”; In this case a String is created in String pool. Now if I initialize String b = “ABC”; And put if condition - if (a==b) this would return true as both a and b point to one literal in pool String object String a = new String (“a”); String b = new String(“a”); If (a==b) returns false in this case as the references point to different objects and (a.equals (b)) returns true. know more here on string:- http://crbtech.in/Java-Training/10-things-string-every-java-programmer-know/
23rd Jun 2018, 4:16 AM
pranit patil
pranit patil - avatar