ch08 - Java Programming Fourth Edition Chapter 8 Arrays...

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

View Full Document Right Arrow Icon
Java Programming Fourth Edition Chapter 8 Arrays
Background image of page 1

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

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 2 Objectives • Declare and initialize an array • Use subscripts with an array • Declare an array of objects • Search an array for an exact match • Search an array for a range match
Background image of page 2
Java Programming, Fourth Edition 3 Objectives (continued) • Pass arrays to methods • Create arrays of Strings • Sort array elements • Use two-dimensional and multidimensional arrays • Use the Arrays class
Background image of page 3

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

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 4 Declaring and Initializing an Array • Array – Named list of data items – All have same type • Declare array variable – Same way as declaring any simple variable – Insert pair of square brackets after type
Background image of page 4
Java Programming, Fourth Edition 5 Declaring and Initializing an Array (continued) • double[] salesFigure; • int[] idNum; • Still need to reserve memory space – salesFigure = new double[20]; – double[] salesFigure = new double[20]; • Subscript – Integer contained within square brackets – Indicates one of array’s variables or elements
Background image of page 5

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

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 6 Declaring and Initializing an Array (continued) • Array’s elements numbered beginning with zero – Can legally use any subscript from 0 through 19 – When working with array that has 20 elements • Work with any individual array element – Treat no differently than single variable of same type – salesFigure[0] = 2100.00;
Background image of page 6
Java Programming, Fourth Edition 7 An Array of 20 salesFigure Items in Memory
Background image of page 7

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

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 8 Initializing an Array • Variable with reference type – Such as array – Holds memory address where value stored • Array names – Represent computer memory addresses – Contain references • Declare array name – No computer memory address assigned – Has special value null • Unicode value ‘\u0000’
Background image of page 8
Java Programming, Fourth Edition 9 Initializing an Array (continued) • Use keyword new to define array – Array name acquires actual memory address value • int[] someNums = new int[10]; – Each element of someNums has value of 0 • char array elements – Assigned ‘\u0000’ • boolean array elements – Automatically assigned value false
Background image of page 9

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

View Full DocumentRight Arrow Icon
10 Initializing an Array (continued) • Assign nondefault values to array elements upon creation – int[] tenMult = {10, 20, 30, 40, 50, 60};
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/13/2011 for the course 332 351 taught by Professor Staff during the Fall '08 term at Rutgers.

Page1 / 43

ch08 - Java Programming Fourth Edition Chapter 8 Arrays...

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

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