CC2203-les04javaIV-for-viewing

CC2203-les04javaIV-for-viewing - 4-1/18Lesson 4: Java IV...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 4-1/18Lesson 4: Java IV – Arrays and VectorsAfter completing this lesson, you should be able to do the following:•Describe how to use arrays of primitive and object references•Process command-line variables•Work with vectors4-2/18What Is an Array?An array is a collection of variables of the same type.•Each element can hold a single item.•Items can be primitives or object references.•The length of the array is fixed when it is created.1248[0][1][2][3]ActionComedyDrama[0][1][2]4-3/18Creating an Array of Primitives1. Declare the array. typeis a primitive, like intand so on.2. Create the array object. 3. Initialize the array elements(optional).Nullpowerspowers124powerstype arrayName;… or …type arrayName; // Create array object syntaxarrayName = new type[size];4-4/18Declaring an Array of Primitives•Create a variable to reference the array object.•When an array variable is declared:–Its instance variable is initialized to null, until the array object has been created.–Its method variable is unknown, until the object is created.int powers; // Example nullpowers4-5/18Creating an Array Object foran Array of Primitives•Create an array of the required length and assign it to the array variable:–The array object is created by using the newoperator.•The contents of an array of primitives are initialized automatically....
View Full Document

Page1 / 18

CC2203-les04javaIV-for-viewing - 4-1/18Lesson 4: Java IV...

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

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