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?