Lecture 24, CS 302-7 and 8, March 16

 

1. Reminders

            A. Program 2 – Due tonight

            B. Program 1

                        i.  Scores posted – forms page of website

                        ii. Regrades – request by next Wednesday 5pm

2. Review

A.     ArrayLists

a.       methods

            1. Copying ArrayLists

                        2. ArrayLists of primitives via wrapper classes

                        3. ArrayLists as parameters and return values to methods

3. Some more array methods

A.     Reminder - .get(index);

B.     .indexOf(<value>)

a.       –1 if no valid index

C.     .lastIndexOf(<value>)

D.     .isEmpty()

E.      reminder – wrapper classes

3. Practice for exam 2

a.       Imagine we wanted to write a program that did the following

a.       Takes an arraylist of Strings

b.      Returns a new arraylist that is the same as the input, except we’ve removed each occurrence after the first of an item

3. Arrays of objects

             A. Examples - Strings, arrays

                        i. This is a good opportunity to talk about arrays of arrays

             B. Remember how arrays of objects are stored (diagram)

             C. We can use these objects stored in arrays as though they are normal objects

                        i. Generally:

                        Type[] name=new Type[size];

                        name[index]=new Type(args);

                        //...add more objects, update them

                        name[index].method(args);

             D. What to do with null?  Skip it!

if(name[i]!=null){ //do something}

             E. Example - ArrayOfStrings.java

5. HW – P2, read 7.1-7.4