Problem of the Day
Problem:
Assume that the ArrayList utility has been imported. What does the following static method do?
public static void unknown(String[] arr)
{
ArrayList<String> arr2 = new ArrayList<String>();
for (String el : arr)
arr2.add(el);
for (int i = 0; i < arr.length; i++)
arr[i] = arr2.remove( (int) (Math.random() * arr2.size()));
}
- Rearranges the elements of
arrinto a random order - Copies the elements of
arrintoarr2in random order - Removes the items from
arrin a random order - Moves a random element from
arrto the beginning of the Array
The correct answer is a. The elements from arr are copied into an ArrayList, then randomly removed from that List one at a time and put into arr again. The original values of arr have been replaced with identical values, now in a different order.