Oop - Lesson 6
Oop - Lesson 6
z
Java String
z
Java String
an object that represents sequence of char values.
char[] ch = {'j','a','v','a','t',’s',’t','i','n',’g'};
is same as
String s = "javatstring";
z
String Literal
new keyword
String Literal
created by using double quotes
String s = “javastring";
String s1 = “javastring";
String s2 = “javastring";
Each time you create a string literal, the JVM checks the "string
constant pool" first. If the string already exists in the pool, a reference
to the pooled instance is returned. If the string doesn't exist in the pool,
a new string instance is created and placed in the pool.
String objects are stored in a special memory
area known as the "string constant pool".
Why Java uses the concept
of String literal?
By new keyword
created by using the new keyword