public static void writeArrayList(ArrayList<?> list, DataOutput out) throws IOException {

    InternalDataSerializer.checkOut(out);

    int size;
    if (list == null) {
      size = -1;
    } else {
      size = list.size();
    }
    InternalDataSerializer.writeArrayLength(size, out);
    if (logger.isTraceEnabled(LogMarker.SERIALIZER_VERBOSE)) {
      logger.trace(LogMarker.SERIALIZER_VERBOSE, "Writing ArrayList with {} elements: {}", size,
          list);
    }
    if (size > 0) {
      for (int i = 0; i < size; i++) {
        writeObject(list.get(i), out);
      }
    }
  }
Writes an <code>ArrayList</code> to a <code>DataOutput</code>. Note that even though
<code>list</code> may be an instance of a subclass of <code>ArrayList</code>,
<code>readArrayList</code> will always return an instance of <code>ArrayList</code>, <B>not</B>
an instance of the subclass. To preserve the class type of <code>list</code>,
{@link #writeObject(Object, DataOutput)} should be used for data serialization. This method
will serialize a <code>null</code> list and not throw a <code>NullPointerException</code>.

@param list the <code>ArrayList</code> to write
@param out the {@link DataInput} to write to

@throws IOException A problem occurs while writing to <code>out</code>

@see #readArrayList
geode-core/src/main/java/org/apache/geode/DataSerializer.java