ReviewofArrays

ReviewofArrays - Array An aggregate data structure Store...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Array An aggregate data structure
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Store several pieces of data using one name int [ ] daysInMonth = new int [12]; Or int daysInMonth [ ] = new int [12]; Or Use an initializer list… int [ ] daysInMonth = {31,28,31,30,31,30,31, 31,30,31,30,31};
Background image of page 2
Arrays are fixed size The size is specified when it is created and it cannot be extended or shrunk but we can create a bigger array and copy the values
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
increaseSize private double [ ] exercises; //instance variable exercises = new double [ 10 ]; //assume this is in constructor private void increaseSize ( ) { double [ ] temp = new double [ exercises.length*2]; for (int i = 0; i < exercises.length; i++) { temp[i] = exercises[i]; } exercises = temp; }
Background image of page 4
Copying Arrays Use the clone method to copy the elements of an array. Example: double [ ] data = new double [ 10 ]; double [ ] prices = new double [ 10 ]; // fill array double [ ] prices = (double [ ] ) data.clone( );
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Copying Arrays Use the System.arraycopy method to copy elements from one array to another
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/13/2008 for the course CSC 216 taught by Professor Miller during the Spring '08 term at N.C. State.

Page1 / 12

ReviewofArrays - Array An aggregate data structure Store...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online