Array Lists

March 28th, 2016

Lecture Recording

Previous Array List material

Lecture Code

Exercise One

Write and test a method public int[] listToVector (ArrayList<Integer> myList) that takes any array list of Integer values and returns a 1D array of int values that contains the elements of the list.

This is very useful method because if, for example, your data values are dynamic for a while but then become static, you use an array list as elements are added and deleted, and then convert to a 1D array for greater efficiency once the values have stabilized.

Note: Write your own method so that you understand how this is done. Do not use the built-in method.

Exercise Two

Modify the above method so that it returns a 1D array where the values are in sorted, ascending order.

Exercise Three

Build the inverse function - vectorToList(int[] myVector)