aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes array.length question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "array.length question" Watch "array.length question" New topic
Author

array.length question

Sriram Chintapalli
Ranch Hand

Joined: Dec 16, 2003
Posts: 59
Hi everyone,
int[] i=new int[10];
System.out.println(i.length);
where in J2SE documentation would I dig to find other variables or methods that can be applied to an array reference variable. Thanks.
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
Hi Sriram,
The field and methods of arrays are described in JLS 10.7 Array Members
a.length
a.clone() // overrides Object.clone()
All the methods inherited from Object:
a.equals(), a.hashCode(), a.toString(), a.getClass()
a.wait(), a.notify(), a.notifyAll()
a.finalize()
[ February 09, 2004: Message edited by: Marlene Miller ]
Sriram Chintapalli
Ranch Hand

Joined: Dec 16, 2003
Posts: 59
Thanks a lot Marlene that helped clear things up about array methods. This should help me remember how different lenght is from Strings' length() method(somehow I always overlook this obvious choice in mock exams)
-sriram
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
Yes, watch out for a.length and s.length(). I suspect that's one you might see on the exam.
I agree, it does help to remember this to understand that array objects have one field and all the methods of class Object (even though they don't have a class definition).
There is another thing from the JLS on arrays that helped me. At the beginning of chapter 10 they say
An array object contains a number of variables... The variables contained in the array have no names...
So I imagine an array object as this amorphous blob containing a sequence of variables (memory locations) without names: a[0] a[1] a[2].
Thank you for letting me know what I said was useful. It helps me to know whether what I say is helpful or not.
[ February 10, 2004: Message edited by: Marlene Miller ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: array.length question