Interview question: Does the array have the length () method? Does the string have the length () method? Does the collection have the length () method?

Source: Internet
Author: User
Package Java basic topic; Import Java.util.arraylist;import java.util.list;/** * Question: Does the array have the length () method? Does the string have the length () method? Does the collection have the length () method? *  Answer: Array for length with the length property, the string to find lengths with the long () method, the set length with a size () method. * So the array does not have the length () method, the string has the length () method, the collection does not have the length () Method! */ public class A2015 Year June 4 _length {public static void main (string[] args) {int[] a = new Int[10];int length = 0;for (int i = 0; i < a.length; i++) {length++;} System.out.println ("length=" + length); int a_length = A.length; String s = "ABCDE"; int s_length = S.length (); list<string> list = new arraylist<string> () List.add ("China"); List.add ("Pakistan"); int list_size = List.size (); SYSTEM.OUT.PRINTLN ("Array length length=" + a_length);//10system.out.println ("string length () =" + s_length);// 5system.out.println ("Length of the collection size=" + list_size);//2}}

Interview question: Does the array have the length () method? Does the string have the length () method? Does the collection have the length () method?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.