Difference between revisions of "Arrays"
From Suhrid.net Wiki
Jump to navigationJump to search (Created page with "== Introduction == * Arrays store multiple variables of the same type. * The array itself is always an object on the heap (even if it is storing primitive elements). == Declar...") |
|||
| Line 7: | Line 7: | ||
== Declaring == | == Declaring == | ||
| − | * int[] scores (Preferred) or int scores[] (Legal, but bad) | + | * int[] scores; (Preferred) or int scores[]; (Legal, but bad) |
| − | * | + | * String[] names; |
| + | * int[][] matrix; | ||
| + | |||
| + | == Constructing == | ||
| + | |||
| + | * int[] scores = new int[10]; | ||
| + | * This will create a new array object on the heap. All the int values will be assigned their default values, Object references will be assigned null. | ||
| + | * The array size must be present ! | ||
| + | * double[] rates = new double[]; //illegal | ||
Revision as of 03:58, 28 June 2011
Introduction
- Arrays store multiple variables of the same type.
- The array itself is always an object on the heap (even if it is storing primitive elements).
Declaring
- int[] scores; (Preferred) or int scores[]; (Legal, but bad)
- String[] names;
- int[][] matrix;
Constructing
- int[] scores = new int[10];
- This will create a new array object on the heap. All the int values will be assigned their default values, Object references will be assigned null.
- The array size must be present !
- double[] rates = new double[]; //illegal