<<< Arrays of objects | Index | Array elements example >>> |
The syntax for referring to an element of an array
arrayName[index]
Code that assigns values to an array of double types
double[] prices = new double[4]; prices[0] = 14.95; prices[1] = 12.95; prices[2] = 11.95; prices[3] = 9.95; //prices[4] = 8.95; // this would throw // ArrayIndexOutOfBoundsException
Code that assigns values to an array of String types
String[] names = new String[3]; names[0] = "Ted Lewis"; names[1] = "Sue Jones"; names[2] = "Ray Thomas";
<<< Arrays of objects | Index | Array elements example >>> |