Possible duplicate:
How are arrays implemented in java? Why doesn't the java.lang.Array class exist? If the java array is an object, should it not extend Object?
I recently thought about Java arrays, and I was wondering what it is?
Are they objects?
- You can call toString () on them (although this only gives you a memory address)
- The next line compiles
Object a = new int[5] ;
However, are they really objects?
- You create a new array
new int[5] ... it's not like a constructor I've ever seen. One would think that it would be new Array<Integer>(5) or something like - If you are looking at the Java API, you will not find an
array class ... You will find an array , but that is not true an array
And what's with iterable properties
- You can go through the array in for each loop, but there is no array
iterator method that I can find
I think an array is just a special exception built directly into the Java language; however, this also raises the question: why do arrays get special treatment? (Why is there no API array? Why is there another type of constructor?)
Any clarification regarding the true nature of the arrays would be appreciated.
PS I have several years of experience in Java, so I know how to use arrays and what they do, I just ask how they are implemented and why?
source share