Simple example to use string in different ways.
Syntax :
Some_string_variable_name.length()
Example :
- public class StringDemo {
- public static void main(String args[]) {
- String palindrome = "Dot saw I was Tod";
- int len = palindrome.length();
- System.out.println( "String Length is : " + len );
- }
- }
Description :
Step 1:Starting of class
Step 2:Start of main function.
Step 3:Define a string "palindrome"
Step 4:Defining and initializing a variable "len". Here the length(number of characters) of the string "palindrome" is copied to variable "len" which is of integer type.
Step 5:Display content of variable "len" to console.
Output:
String Length is : 17