Where is array's length property defined?

前端 未结 7 887
悲哀的现实
悲哀的现实 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:30

    it's public final field , which contains the number of components of the array (length may be positive or zero)

    An array thus has the same public fields and methods as the following class:

    class A implements Cloneable, java.io.Serializable {
        public final int length = X;
        public Object clone() {
            try {
                return super.clone();
            } catch (CloneNotSupportedException e) {
                throw new InternalError(e.getMessage());
            }
        }
    }
    

    more info at

    10.7 Array Members

    http://java.sun.com/docs/books/jls/second_edition/html/arrays.doc.html

提交回复
热议问题