string.length()
String.length() Returns the length of the string in integer.
Syntax
String1.length()
The output is an integer.
Here are some examples with output.
String str = "plus2net";
System.out.println(str.length()); // 8
System.out.println("Welcome to ".length()); // 11
We can list out all the chars of a sting by using for loop
String str = "plus2net";
for(int i=0;i<str.length();i++) {
System.out.println(str.charAt(i));
}
Output
p
l
u
s
2
n
e
t
We used charAt() to get the Char at the position.
« All String functions
« Java
This article is written by plus2net.com team.
plus2net.com