Home> Java> JavaBase> body text

Does Java array have length method?

(*-*)浩
Release: 2019-11-12 11:30:33
Original
4837 people have browsed it

Does Java array have length method?

#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)

Does Java array have length method?

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 array=new ArrayList(); array.add(a); System.out.println(array.size()); 泛型中对象个数是1 }
        
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!