Java中length和length()有什么区别呢?
下文笔者讲述Java中length和length()的不同之处,如下所示
length和length()方法的功能简介
length:
数组的属性
length():
字符串类的方法
但是她的底层是调用数组的length属性
length()源码
/**
* Returns the length of this string.
* The length is equal to the number of <a href="Character.html#unicode">Unicode
* code units</a> in the string.
*
* @return the length of the sequence of characters represented by this
* object.
*/
public int length() {
return value.length;
}
通过以上的源码分析, 我们可以得出的结论是: 两者没有本质上的区别,可以说是一样的效果
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


