Java Program to find length of string using length method


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


String str = "Hello";

5 = str.length();


Example: How to find length of string using length method in Java

Run it Now
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("\nString Length is :" + size);

    }
}

Output:

Enter a String Value :John Smith
String Length is :10