views:

681

answers:

5

I want to find out if length property for Java arrays is an int/long or something else.

+12  A: 

It is an int. See the Java Language Specification, section 10.7.

Greg Hewgill
+1  A: 

The data type is int, not long. Same as the index.

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

DR
+1  A: 

According to the specification, it's an int

Sietse
+1  A: 

In Java Language spec, Arrays you can see in 10.4:

Arrays must be indexed by int values; short, byte, or char values may also be used as index values because they are subjected to unary numeric promotion and become int values. An attempt to access an array component with a long index value results in a compile-time error.

I could not find the type of the length attribute, but it is at least an int; and if it's a long then you can not access elements beyond the max integer length.

So I guess it's a (final) int.

extraneon
A: 

In JavaCard array indexes are shorts, but JavaCard is odd like that. Everywhere else, int like everyone else says.

Tom Hawtin - tackline