code: public static <T> void writeCollection(Collection<T> items, ObjectDataOutput out) throws IOException {
          out.writeInt(items.size());
          for (T item : items) {
              out.writeObject(item);
          }
      }
docs: Writes a collection to an {@link ObjectDataOutput}. The collection's size is written
  to the data output, then each object in the collection is serialized.
  
  @param items collection of items to be serialized
  @param out   data output to write to
  @param <T>   type of items
  @throws NullPointerException if {@code items} or {@code out} is {@code null}
  @throws IOException when an error occurs while writing to the output