Wednesday, June 10, 2009

How to declare and initial array in java

Declares and initial an array in Java
 
int [] anArray;                         // can also be written as :  int anArray [];
 
int [] anArray = null;
int [] anArray = new int[10];    // can also be written as :  int anArray [] = new int[10];
 
String [] array = {"A", "B", "C"};
String [][] names = {{"Mr. ", "Mrs. ", "Ms. "}, {"Smith", "Jones"}};
 
Create an new Array object as a parameter in function
getNames( new String [] {"Smith", "Jones", "Oehler"} );