code: @Override
      @SuppressWarnings("unchecked")
      public <E> E[] toArray(E[] a) {
  
          if (a.length < size()) {
              a = (E[]) Array.newInstance(a.getClass().getComponentType(), size());
          }
  
          int aIndex = 0;
          synchronized (this) {
  
              synchronized (lock) {
                  //First add anything in the expedited buffer
                  //Check if we wrap around the end of the array before iterating
                  if (expeditedPutIndex > expeditedTakeIndex) {
                      for (int i = expeditedTakeIndex; i <= expeditedPutIndex; i++) {
                          a[aIndex] = (E) expeditedBuffer[i];
                          aIndex++;
                      }
                  } else {
                      //We wrap around the array. Loop through in two passes(upper and lower)
                      for (int i = expeditedTakeIndex; i < expeditedBuffer.length; i++) {
                          a[aIndex] = (E) expeditedBuffer[i];
                          aIndex++;
                      }
                      for (int i = 0; i < expeditedPutIndex; i++) {
                          a[aIndex] = (E) expeditedBuffer[i];
                          aIndex++;
                      }
                  }
  
                  //Now add the items in the main buffer
                  //Check if we wrap around the end of the array before iterating
                  if (putIndex > takeIndex) {
                      for (int i = takeIndex; i <= putIndex; i++) {
                          a[aIndex] = (E) buffer[i];
                          aIndex++;
                      }
                  } else {
                      //We wrap around the array. Loop through in two passes(upper and lower)
                      for (int i = takeIndex; i < buffer.length; i++) {
                          a[aIndex] = (E) buffer[i];
                          aIndex++;
                      }
                      for (int i = 0; i < putIndex; i++) {
                          a[aIndex] = (E) buffer[i];
                          aIndex++;
                      }
                  }
              }
          }
  
          if (a.length > size()) {
              a[size()] = null;
          }
          return a;
      }
docs: /*
  @awisniew - ADDED
  
  (non-Javadoc)
  
  @see java.util.Collection#toArray(T[])