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