CPS 109 Lecture Notes - Lecture 5: Dynamic Array, Instance Variable

61 views4 pages

Document Summary

Container object that holds a fixed number of values of a single type. Length of array is established when it is created, this then becomes fixed. Gives faster access than other data structures in java. Element: each item in an array, and each element can be accessed by its numerical index, these are actually variables. An array can hold primitive elements but an array is not a primitive element itself. New boolean array always defaults to false, similarly, an array of object references defaults to null when created. Declaring a variable to refer to an array: eg: int[] anarray, two components: array type, and array name. Creating, initializing, and accessing an array: common error: allocating array reference but not the actual array. Even arrays must be initialized before they can be used: new operator. Eg: anarray = new int[10]; and then assign values to each element.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions