File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Doubt on Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Doubt on Arrays" Watch "Doubt on Arrays" New topic

Doubt on Arrays

sanyasirao nali

Joined: Oct 14, 2012
Posts: 6

Why arrays are started with 0(zero) index...?

example: a[5]={23,5,34,23,21}
here a[0]=23,a[1]=5 . . . . . . ,a[4]=21.
here a[] started with a[0] not a[1]......why arrays are starting with 0(zero) index...?

Thankyou in Advance.
dennis deems
Ranch Hand

Joined: Mar 12, 2011
Posts: 808
An array is not merely a logical structure; it is a contiguous chunk of memory space. What makes using arrays so blindingly fast is that we can get any array element by applying an offset ( the index number ) to the start of the array. To get the first array element, we go to the start of the array and apply an offset of zero. To get the fifth element we go to the start of the array and apply an offset of four.
Tony Docherty

Joined: Aug 07, 2007
Posts: 1937
Why arrays are started with 0(zero) index...?

Arrays in Java start at 0 but not all languages take this approach.
See this thread for an explanation:
I agree. Here's the link:
subject: Doubt on Arrays
Similar Threads
ArrayIndex OutOfBoundsException?
when java is 0 indexed
searching for "\d*" in a string
doubt on group() in Matcher class
Out of bounds Exception