Lecture 23, CS 302-6, October 26
- Reminders
- 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…
- Program
1
i.
Scores posted – forms page of website
ii.
Regrades – request by next Wednesday 5pm
- Review
- ArrayLists
- Finish
Inventory.java
- Copying
ArrayLists
- If
you just set them equal, this copies the reference, just like arrays
- Method
1 : Piece by piece (tedious) – using for loop
- Method
2 : Use constructor
i.
Given names:
ArrayList<String>
namesCopy=new ArrayList<String>(names);
- ArrayLists
of primitives using wrapper classes
- ‘wrappers
and auto boxing’
- wrappers
– wrapper classes for primitive types
- 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;
- Passing
ArrayLists
- Reminder
– can pass objects as parameters
i.
Example – Random random in Program2
- 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)
{
}
- Exam 1
returned
- 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.