code: @SuppressWarnings("unchecked")
      public static <T> T[] toArray(Collection<T> collection) {
          if (collection == null) {
              return null;
          }
  
          T item = null;
          for (T i : collection) {
              if (i != null) {
                  item = i;
                  break;
              }
          }
  
          return item == null ? null : toArray(collection, (Class<T>) item.getClass());
      }
docs: Converting {@link java.util.List List} into array.<br/>
  Note: array type is determined by class of the first non-null element in the list.
  If there is no elements or all elements are null, null will be returned.<br/>
  Elements in the list should be exactly of requested type, not its descendants.