free ebooks

 

 

 Home
105 Computers & InternetProgramming > Java  
Data Structures Through Java

Before using the variable a, it must be properly initialised, either by assignment to another properly initialised variable of the same type, or directly as in

a = new int[20];  

This instructs the operating system to find consecutive storage for 20 integers and place a reference to that block of memory in the variable a. This is sometimes known as allocating the array. Note that the operations of declaration and allocation can be done together as in

int[] a = new int[20];  

Either way, elements of the array can now be accessed by index as in

a[2] = 173;  

which assigns the integer 173 to the array element 2. Elements can also be accessed using an index variable as in a[i]. The variable i must be of type byte, short or int, but int is the most common.

Download

 Additional Info
 
 No. 261
 Posted on 8 June, 2006
 
218
 
 
Bookmark This Page
Facebook Twitter stumbleupon

Share
Email
Google

Link to us from your website or blog by using the code below in your html
   
@2008 ebooklobby privacy policy email: info [at] goaheadweb.co.uk