Arrays - Part 2

Notes

PA3 - Return - Lessons learned PA3 case study
Homework review - Review of questions that are still wrong.

Review of lab - ArrayPlay.java  Reading reference (8.2) Note: This is not exactly like your assignment.

The final piece to the header: public static void main( String args[])  What does this mean?

And how do we use it?  Command line arguments: Argue.java Book reference (8.12)


Arrays as Reference Types

Passing arrays to methods

Returning arrays from methods

Side effects


Arrays of Objects - What does an array of objects hold?

3 part build

  1. Declare the array
  2. Instantiate the array
  3. Instantiate each object of the array

Example ManyDice.java



Variable Length parameters

VarArgsDemo2.java (Book reference 8.12)
Some specialized Array class tools.

Things to remember about arrays:

Feature Syntax Example
Declaration data-type [] variable-name; int [] gradeArray;
Card [] deck;
Declaration
(alternative)
data-type variable-name[]; int gradeArray [];
Card deck [];
Initializer list data-type [] list = { value, value, ... value} String [] names = { "bob", "ann", "amy", "sue", "sam"};
Instantiation new data-type[int-value] intArray = new int [25];
deck = new Card [cardCount];
Instantiation and initialization new data-type[] { value, value, ... value } names = new String [] { "bob", "ann", "sue", "sam" }; return new int [] {0};
Referring to the
array as a whole
var-name return deck;
intArray = grades;

array2.equals(array1);
(What do you think this does compares?)

arrLength = names.length;

Specialized Arrays methods java.util.Arrays.fill(grades, 100);
java.util.Arrays.equals(section1, section2);
java.util.Arrays.sort(names);
java.util.Arrays.toString(names)
Referring to array elements var-name[int-value] return deck[0];
intArray[ii] = grades[jj];
rank = deck[ii].getRank();
while (intArray[ii] == 5)