Why is array indexing in Java start with 0?

Java uses zero-based indexing because c uses zero-based indexing. C uses zero-based indexing because an array index is nothing more than a memory offset, so the first element of an array is at the memory it's already pointing to, *(array+0).

See also Wikipedia's array indexing in different languages?


To expand upon @Kevin's answer, I take this quote from an answer on Programmers.SE:

The index in an array is not really an index. It is simply an offset that is the distance from the start of the array. The first element is at the start of the array so there is no distance. Therefore the offset is 0.

Further, if you want to learn more about how different languages do their array indexing, then look at this exhaustive list on Wikipedia.

Tags:

Java

Arrays