Let’s learn string length() method in java.
String length() method in java
String length() method returns length of this string.
The length of the sequence of characters represented by this object.
String length() method is specified by CharSequence interface.
The length is equal to the number of Unicode code units in the string.
Syntax
public int length()
Here’s String length() method example.
public class StringLengthJava { public static void main(String[] args) { String str1 = "flowerbrackets"; String str2 = "helloworld"; System.out.println("string length : " + str1.length()); System.out.println("string length : " + str2.length()); } }
Output:

Also read – Factorial program in java