String str = "love jave";
int s = 0;
s = str.length();
if(s==9){
System.out.println("字符串的长度为:"+s);
}
else{
System.out.println("发生错误");
}
运行效果如下:
字符串的长度为:9
API说明
public int length()
Returns the length of this string. The length is equal to the number of
Unicode code units in the string.
-
Specified by:
-
length
in interfaceCharSequence
Returns:
- the length of the sequence of characters represented by this object.