code: public static <T> T[] toArray(final Collection<T> collection) {
  
          T next = getFirstNotNullValue(collection);
          if (next != null) {
              Object[] objects = collection.toArray();
              @SuppressWarnings("unchecked")
              T[] convertedObjects = (T[]) Array.newInstance(next.getClass(), objects.length);
              System.arraycopy(objects, 0, convertedObjects, 0, objects.length);
              return convertedObjects;
          } else {
              return null;
          }
      }
docs: Convert given collection to an array.
  
  @param collection
  source collection.
  @return an array has full given collection element and order by
  collection index.