#There is no length() method for arrays in Java, only the length attribute. Array array.length returns the length of the array.
String has a length() method, and str.length() returns the length of the string. (Recommended learning: java course)
size() is for generic collections and is used to calculate the object size. Check the generics How many elements.
public static void main(String[] args) { String []list={"ma","cao","yuan"}; String a="macaoyuan"; System.out.println(list.length); 数组长度是3 System.out.println(a.length()); 字符串长度是9 List<Object> array=new ArrayList(); array.add(a); System.out.println(array.size()); 泛型中对象个数是1 }
The above is the detailed content of Does Java array have length method?. For more information, please follow other related articles on the PHP Chinese website!