If you have trouble, post the code you expect to compile and the compiler messages you get.
ArrayList<Integer> list = new ArrayList<Integer>(); // presumably the list is populated int array = new int[list.size()]; // use a for loop to populate the array return array;
maslyak wrote:This is wrong. The API clearly states:
We can transform ArrayList<Integer> into Integer by calling toArray() method in ArrayList, which will not copy an array.
The returned array will be "safe" in that no references to it are maintained by this list. (In other words, this method must allocate a new array). The caller is thus free to modify the returned array.