Flashcards
Arrays
Cards in this deck (11)
- 1Array- ordered list of values
- a particular value is referenced using 'array name [ ]' - 2Array Elements- store multiple values of the same type
- can be primitive type or object reference
- - 3Declaring 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]; - 4Using Arrays- iterator version of the for loop can be used when processing array elements:
for (int variablename: scores)
System.out.println (variablename); - 5Bounds Checking- once created, array size is fixed
- java will recognise if a element is outside of array index and prints 'ArrayIndexOutOfBoundsException' - 6Bounds Checking (cont.)- every array has a public constant called 'length'
- referenced: variablename.length
- 'length' holds the number of elements, not the largest index - 7Initialiser 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'}; - 8Initiliser Lists- when intialiser is used;
- the 'new'' operator is not used
- no 'size'value is specified
- can only be used in the array declaration - 9Array as Parameters- array can be passed to a method as a parameter
- - 10Array 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"}; - 11SummaryArray concept:
- Vector / matrix / table: of data elements, all of same type
- Vector with subscript, matrix with subscripts
Information
- Description
- Programming Flashcards on Arrays, created by Tony Meman on 15/08/2016.
- Created by
- Tony Meman
- Views
- 19
- Tags
- Rating