Lecture 23, CS 302-6, October 26

  1. Reminders
    1. Program 2 – Due Friday night

                                                               i.      EC – posted

                                                             ii.      Extra office hours – 3-4 Wednesday, 12:30-2:30 Thursday, Friday TBD

                                                            iii.      Initializing 2d arrays – how do we know the size of the array?  Based on another array…

    1. Program 1

                                                               i.      Scores posted – forms page of website

                                                             ii.      Regrades – request by next Wednesday 5pm

  1. Review
    1. ArrayLists
  2. Finish Inventory.java
  3. Copying ArrayLists
    1. If you just set them equal, this copies the reference, just like arrays
    2. Method 1 : Piece by piece (tedious) – using for loop
    3. Method 2 : Use constructor

                                                               i.      Given names:

ArrayList<String> namesCopy=new ArrayList<String>(names);

  1. ArrayLists of primitives using wrapper classes
    1. ‘wrappers and auto boxing’
    2. wrappers – wrapper classes for primitive types
    3. auto-boxing

                                                               i.      this means that you can still store the primitive values in the array list – it just needs the type of the wrapper class.

                                                             ii.      Example on board of what it means to be boxed:

Double wrapper=29.95;

double x=wrapper;

  1. Passing ArrayLists
    1. Reminder – can pass objects as parameters

                                                               i.      Example – Random random in Program2

    1. Like Arrays, and every other type we’ve encountered so far, we can pass ArrayLists as parameters to methods, and return them from methods.

                                                               i.      Must specify Type Parameter in both cases in method declaration.

public static ArrayList<Integer> methodName(ArrayList<Integer> aList)

{

 

}

  1. Exam 1 returned
  2. HW – Look at exam 1, think about what you got wrong, and make sure you understand why the correct answer is correct.  Come to me if you don’t J.  Also, review P1 comments.  Finally, work on P2.