Strings in Java
Although, the concept of String is usually introduced after you have learned the concept of Class, we think that it is an important concept and its usage does not require a lot of theoretical background.
The String class is essentially an array of character strings. An String is decalred as follows
String FirstName = "Michael";
Notice the capital S in the keyword String.
Strings are constants and their values cannot be changed after they are created. Let us start our very simple java code that just declares String and prints first and last name.
|
If you compile and run, it simply prints the name preceded by Hi.
Hi Roger William |
Finding Length of a String
You can use the length() method to find the length of a String.
|
If you compile and run, it simply prints the name preceded by Hi.
length of string is 46 |