Where is array's length property defined?

前端 未结 7 819
悲哀的现实
悲哀的现实 2020-11-22 13:41

We can determine the length of an ArrayList using its public method size(), like

ArrayList arr = new ArrayL         


        
7条回答
  •  难免孤独
    2020-11-22 14:17

    The keyword length acts like a data filed defined. When using in an array, we can use it to access how many elements in an array. Regarding to String[], we can invoke length() method defined in String class. With regard to ArrayList, we can use size() method defined in ArrayList. Note that when creating an array list with ArrayList<>(capacity), the initial size() of this array list is zero since there is no element.

提交回复
热议问题