1: @author Frank M. Carrano, Timothy M. Henry 2: @version 5.0 3: /** Retrieves all entries that are in this bag. 4: @return A newly allocated array of all the entries in the bag. */ 5: public T[] toArray() 6: { 7: // The cast is safe because the new array contains null entries. 8: @SuppressWarnings("unchecked") 9: T[] result = (T[])new Object[numberOfEntries]; // Unchecked cast 11: for (int index = 0; index < numberOfEntries; index++) 12: { 13: result[index] = bag[index]; 14: } // end for 15: 16: return result; 17: } // end toArray