Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

where to check the length instance variable for an Array

 
sai prasanna
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all
we have length instance variable for an array how to view this instance variable as we view methods in java API

thanks in advance
sai prasanna
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An array is an object and it is an instance of a class which ought to document the length attribute. I don't think it's in the API docs at all, though. Arrays are one of those dirty little corners in the language where they can say "Everything works like this ... except array"

You can try to explore the class through reflection. This much works:

Look into the Class class for ways to explore the methods and attributes.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your question is not clear.

The "length" property that arrays have in Java is not a real instance variable. It's just a special Java keyword. It's part of the Java language, not of the standard API, so it isn't documented in the API documentation.

What is it exactly that you want to know?
 
Dan Patterson
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, length is a read-only data field that specifies the number of elements in the array.
 
Vlado Zajac
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not defined in API doc, it is defined in the Java Language Specification
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic