Possible Duplicate:
How are arrays implemented in java?
Why isn’t there a java.lang.Array class? If a java array is an Object, shouldn’t it extend Object?
I was recently thinking about Java arrays and I was wondering what exactly are they?
Are they objects?
- You can call toString() on them (even though it only gives you the
memory address) - The following line compiles
Object a = new int[5]
;
However, are they really objects?
- You create a new array by
new int[5]
...this is like no constructor I've ever seen. One would think it would benew Array<Integer>(5)
or something of the sort - If you look through the Java API you won't find an
array
class...You'll findArray
but this isn't truely an array
And what's up with it's iterable properties
- You can go through an array in a for each loop, but there is no
iterator
method of array that I can find
I think array is just some special exception built directly into the Java language; however, this also poses the question: why are arrays given special treatment? (Why isn't there an Array API? Why is there a different type of constructor?)
Any clarification regarding the true nature of arrays would be appreciated.
P.S. I have a few years experience in Java, so I know how to use arrays and what they do, I'm just asking how exactly they are implemented and why?