In Java, String is collections of character sequence and they are used as an Object. we use the Java.lang.String is the package used for string object creation. Java Strings are non - mutable in nature. Alteration is not allowed at once the object is created. Each time a string is created, an object is initialized of that type. The characters are mentioned within the double quotes which string initialization
String String_Name = "My Java Code";
String s=new String(“My Java Code”);
So what do we mean by Sequence of Character, see below
Java String provide a lot of string manipulation methods such as compare(), split(), length(), equals(), compareTo(), substring etc
Following are the two different ways of string creation
By using the string literal
By using the new keyword
String literal
Using double quotes the java string literal is created
String a = “imagination”;
The object of the string are stored in the string constant pool
By using new keyword
String s = new String(“imagination”);
In this case, one reference variable and two objects are created. The string object is placed by the JVM in the normal pool memory and in the string constant pool the actual literal is placed
Online website Knowledge2life
|