13. Practice A
Two practice problems covering the basic properties (and gotcas) of ArrayList.
ArrayList and Random
- Make an ArrayList of Integer.
- Add in a random number (10 through 20) of random integers in the range [-50,50].
- Change 3 random locations in your arraylist to -500.
- Remove the items at index 2 and 6 and print out their sum.
- Print out the number of items in the ArrayList.
- Modify the list by removing all of the negative numbers.
- Print the list.
Null
String bad = null;
String empty = "";
-
Input an array of integers.
public static void prob2(int[] xs) -
Output an ArrayList
of the same length. Translate each of the numbers into a string:
0 -> null 1 -> "One" 3 -> "Three" _ -> "." -
Print the total # characters in all of the Strings in the ArrayList.
-
Now remove all of the “Three” strings in the ArrayList.
-
Print the remaining ArrayList.