Creado por Tony Meman
hace más de 8 años
|
||
Pregunta | Respuesta |
Array | - ordered list of values - a particular value is referenced using 'array name [ ]' |
Array Elements | - store multiple values of the same type - can be primitive type or object reference - |
Declaring Arrays | - eg. int [ ] variablename = new int [10] - this example sets the size of the array at 10 integers - eg: double[ ] prices = new double[500]; - eg: boolean[] flags; flags = new boolean[20]; - eg: char[ ] codes = new char[1750]; |
Using Arrays | - iterator version of the for loop can be used when processing array elements: for (int variablename: scores) System.out.println (variablename); |
Bounds Checking | - once created, array size is fixed - java will recognise if a element is outside of array index and prints 'ArrayIndexOutOfBoundsException' |
Bounds Checking (cont.) | - every array has a public constant called 'length' - referenced: variablename.length - 'length' holds the number of elements, not the largest index |
Initialiser Lists | - can instantiate and fill an array in one step - values delimited by braces and separated by commas - eg: int[] units = {147, 323, 89, 933, 540, 269, 97, 114, 298, 476}; - eg. char[] letterGrades = {'A', 'B', 'C', 'D', 'F'}; |
Initiliser Lists | - when intialiser is used; - the 'new'' operator is not used - no 'size'value is specified - can only be used in the array declaration |
Array as Parameters | - array can be passed to a method as a parameter - |
Array of Objects | - elements of an array can be object references - eg: store 5 references to String objects String[] words = new String[5]; - does NOT create the objects themselves - unless using literals - eg: String[] verbs = {"play", "work", "eat", "sleep"}; |
Summary | Array concept: - Vector / matrix / table: of data elements, all of same type - Vector with subscript, matrix with subscripts |
¿Quieres crear tus propias Fichas gratiscon GoConqr? Más información.