Java Program to find the length of string using length method


In this program, You will learn how to find the length of string using length method in java.


String str = "Hello";

5 = str.length();

Example: How to find the length of string using length method in java.

import java.util.Scanner;

class Main {
    public static void main(String args[]) {

        int size;
        String str;
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter a string value:");
        str = sc.nextLine();

        size = str.length();
        System.out.println("String length is:" + size);

    }
}

Output:

Enter a string value:Xiith.com
String length is:9