code: @SuppressWarnings("unchecked")
      public static <K, T extends Collection<K>> Collection<K> instantiateCollectionType(Class<T> collectionType, int length) {
          if (collectionType == null) {
              throw new IllegalArgumentException("Method parameter collectionType must not be null.");
          }
  
          T collection;
          // This includes java.util.Collection
          if (collectionType.isAssignableFrom(List.class)) {
              collection = (T) new ArrayList<K>(length);
          } else if (collectionType.isAssignableFrom(Set.class)) {
              collection = (T) new LinkedHashSet<K>(length);
          } else {
              throw new IllegalArgumentException("Unable to instantiate a collection of type " + collectionType +
                      ". Only collections assignable from " + List.class + " or " + Set.class + " are supported.");
          }
          return collection;
      }
docs: Provides an implementation instance for the desired collection type.
  Example: If the collection type is {@link List}, a suitable list implementation is instantiated.
  
  @param collectionType must not be <code>null</code>.
  @return never <code>null</code>. Throws an {@link IllegalStateException}
  if the collection type is not supported.