# Unit 4B - Code Practice with ArrayLists

Each coding exercise has its own folder. Open its `.java` file and press **Run** to try it. **Run Tests** checks every graded exercise in this lesson at once.

## Exercise 1

Fix the code so that it compiles. The code should instantiate an ArrayList of Strings `names` and fill it with the Strings from the array `friends`. It should then print out `names`.

> Open the `01-ArrayListPractice1` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (1 test).

## Exercise 2

Fix the following class so that it will compile and the method `reverse` will return an ArrayList containing Integers in the reversed order of the ArrayList parameter `list`. Hint: for this solution, only one line needs to be added to the for-loop inside of the `reverse` method.

> Open the `02-ArrayListPractice2` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

## Exercise 3

Fix the following method `printEvenIndex` so that it will print out the Integers at even indices of the passed-in ArrayList `list`.

> Open the `03-ArrayListPractice3` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (3 tests).

## Exercise 4

Fix the following method `printEvenElements` so that it will print out all of the even Integers that are in the passed-in ArrayList `list`.

> Open the `04-ArrayListPractice4` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

## Exercise 5

Rewrite the code so that it fills the ArrayList `values` with the elements of the array `nums` using a for-each loop instead of a `for` loop.

> Open the `05-ArrayListPractice5` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

## Exercise 6

Finish the following method `sumNegValues` to return the sum of all of the negative numbers in the ArrayList `list`, the parameter.

> Open the `06-ArrayListPractice6` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

## Exercise 7

Finish the following method `removeLongStrings` that checks each element of the passed in ArrayList `list` and removes any that are strictly longer than 4 characters.

> Open the `07-ArrayListPractice7` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

## Exercise 8

Fill in the method `shiftLeftOne` to shift all of the elements of the passed-in ArrayList `list` left by one. The original first element should be wrapped to the back of the list after the shift. Ex: {1, 2, 3, 4} should turn into {2, 3, 4, 1}

> Open the `08-ArrayListPractice8` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

## Exercise 9

Finish the method `moveSmallest` so that it finds the smallest value in the passed-in ArrayList `list` and moves it to the front of the list.

> Open the `09-ArrayListPractice9` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

## Exercise 10

Finish the method `findLongest` to find and return the longest String in the ArrayList of Strings `list`.

> Open the `10-ArrayListPractice10` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).
