Completing this sequence of exercises will reacquaint you with the ArrayList<E>
Collection and its implementation of some of the important List<E> methods including size, isEmpty, get, add, remove and compareTo.
Tasks.
- Create a project called ArrayListOps and add a driver by the same name.
- Recall the Really, Really Random Number Generator circuit from the Christmas holidays. About a third of the way down the page the author discusses John von Neumann's algorithm for evenly weighting a random set of binary elements (adjacent screen capture). Let's put his algorithm to the test,
- create and populate a 100-cell boolean array, named uneven, with random values
- determine and display the respective counts of uneven
- create an ArrayList<Boolean> named evenly, and, using von Neumann's algorithm, traverse uneven in the manner he describes and use the outcomes to populate evenly.
- determine and display the respective counts of evenly.
- Add the class field: ArrayList<String> names.
- In the main method, instantiate names and, immediately after, display the size() of the list.
- Use ArrayList's add(E) method to populate the list with a few names and then display the size of the list.
- Display the first object in the list.
- Display the last object in the list.
- Display the object in the list from back to front.
- Remove the first name in the list, display to verify, insert the name at the beginning again and display to verify. (4 statements)
- Make the first name the last name (1 statement). Display to verify.
- Remove the alphabetically-first name, reinsert it at the beginning of the list and display the list to verify.
- Implement a sort method that accepts names as the explicit parameter and returns a new list in alphabetic order. Display to verify.