Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

arrays

  Asked By: James    Date: Mar 12    Category: Java    Views: 625
  

I have an array defined as follows:

Object[] array = Object[4];

I know I can find the number of the allocated items like this:

int n = array.length;

Now the question: what is length relative to array? A sort of member variable?
Belonging to what class? And what other similar constructions are possible?
Like:

array.<something>

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Cambria Lopez     Answered On: Mar 12

length is a variable to determine the length  of
the array. You can use other variable but why? The
majority of us use .length because it is very
descriptive and precisely.

 
Answer #2    Answered By: Topaz Ramirez     Answered On: Mar 12

I want to know what length  is from the language syntax point of view, and
subsequently what other similar constructions are possible, not to do the same
thing as length (retrieve the length of the array), but to do other operations
on the array. You say length is a variable. Where is it defined?

 
Answer #3    Answered By: Angie Bennett     Answered On: Mar 12

Is all you wrote here cited from that book, or just the first paragraph? Anyway,
I was aware of the fact that an array  is condidered to be a first-class Object,
BUT the class  Object doesn't have the property length. That's my point.

Is your third paragraph (that begins with "length" is a property...) also cited
from that book? If so, I will be satisfied with that answer. If not, how do you
know it?

 
Answer #4    Answered By: Ray Lawrence     Answered On: Mar 12

Core Java 2 (Volume I Fundamentals) -

"In Java, arrays  are first-class objects. You are
better off not thinking about how arrays are
implemented in Java - accept them as objects that
exist in and of themselves".

Array is a structure of pre-defined length  provided by
the Java language and it can contain values of the
same type.

"length" is a property provided by the Java language.
At the moment, there are no such properties other than
"length"...

 
Didn't find what you were looking for? Find more on arrays Or get search suggestion and latest updates.




Tagged: