Java program to find length of a string


Following program shows you how to find length of a string.
In this program we get string from user and prints the length using .length()

import java.util.Scanner;

public class StringOperations1 {

	public static void main(String[] args) {

		String input;

		Scanner in = new Scanner(System.in);

		System.out.println("Please enter the string:");

		input = in.nextLine();

		int lengthOfString = input.length();

		System.out.println("Length of the given string is: " + lengthOfString);

	}
}

Output:

Please enter the string:
hello
Length of the given string is: 5