code: @SuppressWarnings("unchecked")
      public E[] toArray(E[] a) {
          int n = data.size();
          if (a.length < n) {
              a = (E[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), n);
          }
          
          for (int i = 0; i < n; i++) {
              a[i] = get(i).x;
          }
          
          for (int i = n; i < a.length; i++) {
              a[i] = null;
          }
          
          return a;
      }
docs: Returns an array containing all of the elements in this dataset in
  proper sequence (from first to last element); the runtime type of the
  returned array is that of the specified array. If the dataset fits in
  the specified array, it is returned therein. Otherwise, a new array
  is allocated with the runtime type of the specified array and the size
  of this dataset.
  <p>
  If the dataset fits in the specified array with room to spare (i.e., the
  array has more elements than the dataset), the element in the array
  immediately following the end of the dataset is set to null.
  
  @param a the array into which the elements of this dataset are to be
  stored, if it is big enough; otherwise, a new array of the same runtime
  type is allocated for this purpose.
  @return an array containing the elements of this list.