public static void writeSet(Collection<?> set, DataOutput out) throws IOException {
    checkOut(out);

    if (set != null) {
      final int size = set.size();
      writeArrayLength(size, out);
      if (logger.isTraceEnabled(LogMarker.SERIALIZER_VERBOSE)) {
        logger
            .trace(LogMarker.SERIALIZER_VERBOSE, "Writing Set with {} elements: {}", size, set);
      }
      for (Object element : set) {
        writeObject(element, out);
      }
    } else {
      writeArrayLength(-1, out);
      if (logger.isTraceEnabled(LogMarker.SERIALIZER_VERBOSE)) {
        logger
            .trace(LogMarker.SERIALIZER_VERBOSE, "Writing Set with {} elements: {}", -1, null);
      }
    }
  }
Writes a {@code Set} to a {@code DataOutput}.
<P>
This method is internal because its semantics (that is, its ability to write any kind of {@code
Set}) are different from the {@code write}XXX methods of the external {@code DataSerializer}.

@throws IOException A problem occurs while writing to {@code out}
@see #readSet
@since GemFire 4.0
geode-core/src/main/java/org/apache/geode/internal/InternalDataSerializer.java