ArrayList Practice
Check out the ArrayList slides to make sure you understand how to use all of the methods and to make sure you understand the generic syntax.
We’ll just spend today and a little of Wednesday doing some mechanical exercises to get you used to the syntax and then dive into a larger project.
Negative Integers
Write a method that prints all negative values in an ArrayList of Integers. Use an enhanced for loop.
Max Length
Write a method maxLength that takes an ArrayList of Strings as a parameter and that returns the length of the longest string in the list. If your method is passed an empty list, it should return 0. Use the enhanced for loop syntax.
Remove even-indexed
Write a method that changes every even-indexed element of an ArrayList of strings to the empty string.
Swap
Write a method that takes an ArrayList of Strings and two integer indexes as parameters. Your method should swap the values at the two indexes.
Grocery List
- Add an item to the list.
- Remove an item on the list (if it is on the list – otherwise inform them that the item was not on the list).
- Replace an item on the list. Display the list and the total number of items in the list.
- Quit




