Gadgets

Sunday, 13 December 2015

find length of the string in java

To find length of the string we use length() method
length():- length() is final method, it is applicable for String Objects. Length() method returns number of characters present in the String.
import java.util.Scanner;
public class PalindromeTest {
    public static void main(String[] arg){
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter Name :");
        String name=sc.nextLine();
        System.out.println("length of the String : "+name.length());  
                               /*
                               length() is final method, it is useful to find the length of the string
                               */
    }
}
/*
Enter Name :
java
length of the String : 4

*/



1 comment: