code: public static <T> JSONArray toJSONArray(final Collection<T> collection) {
          final JSONArray ret = new JSONArray();
  
          if (null == collection) {
              return ret;
          }
  
          for (final T object : collection) {
              ret.put(object);
          }
  
          return ret;
      }
docs: Converts the specified {@link Collection collection} to a {@link JSONArray JSON array}.
  
  @param <T>        the type of elements maintained by the specified collection
  @param collection the specified collection
  @return a {@link JSONArray JSON array}