What  is  Java  Arrays

(For  Array.java,  Array2.java,  Array3.java)
Sample Program That Uses  Array

Structure  of  Java  Arrays

The Java array depicted above has 7 elements. Each element in an array holds a distinct value. In the figure, the number above each element shows that element's index. Elements are always referenced by their indices. 

The first element is always index 0. This is an important point, so I will repeat it! 

The first element is always index 0. Given this zero-based numbering, the index of the last element in the array is always the array's length minus one. So in the array pictured above, the last element would have index 6 because 7 minus 1 equals 6.
 

Java  Array  Declaration

An array variable is declared the same way that any Java variable is declared. It has a type and a valid Java identifier. The type is the type of the elements contained in the array. The [] notation is used to denote that the variable is an array. Some examples:
 

Java  Array  Initialization

Once an array variable has been declared, memory can be allocated to it. This is done with the new operator, which allocates memory for objects. (Remember arrays are implicit objects.) 

The new operator is followed by the type, and finally, the number of elements to allocate. The number of elements to allocate is placed within the [] operator.

Do you have a Java Problem?
Ask It in The Java Forum

Java Books
Java Certification, Programming, JavaBean and Object Oriented Reference Books

Return to : Java Programming Hints and Tips

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.
The site www.erpgreat.com is not affiliated with or endorsed by any company listed at this site.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.