Java Online Compiler
Example: StringLength in Java
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// StringLength public class Main { public static void main(String[] args) { // Step 1: Initialize a string String text = "Java Programming"; // Step 2: Get the length of the string using the length() method int length = text.length(); // Step 3: Print the string and its length System.out.println("The string is: \"" + text + "\""); System.out.println("Its length is: " + length); // Step 4: Check length of an empty string String empty = ""; System.out.println("Length of empty string: " + empty.length()); } }
Output
Clear
ADVERTISEMENTS