求长三剑客length,length(),size()
1.length是数组的属性而不是方法,用来求数组长度。
int[] a={1,2,3,4};
int len = a.length;
2.length()是字符串的方法,用来求字符串长度。
String str = "abcdefg";
int len = str.length();
@return the length of the sequence of characters represented by
this object.
解释为由该对象所代表的字符序列的长度,因此终究还是要找length这个底层的属性;
3.size()是集合List,Set和Map求长的方法。
list的底层实现本质就是数组,一次size()方法最后要找的也是数组的length属性;