Concept of String Class
Topics
Advertisements
String Class:
Java Class Library (JCL) contains a class called string, which is available under the java.lang package. It allows the user to create an object or declare a variable to store a set of characters. Hence, a set of characters within double quotes is known as a String.
String Variable
String variable is a named memory location that contains a string constant or string literal. The value of variable may change in the program. A variable declared with data type String gains the capability of storing a set of characters.
Assigning a string
A string can be assigned in two different ways, as follows:
1) Direct Assignment: In this method, a string constant is directly assigned to a string variable. Syntax: <String data type> <Variable> = <String Literal>
2) Assignment by using new Keyword: It allows the user to assign a string object with a string literal or variable by using new keyword with the help of a constructor. Syntax: <class name> <object name> = new <constructor> <String literal/variable>;
By default, String data type creates a character array to store a set of characters in different cells. Thus, assigning a string means assigning a character array to a String object.
