Here you can find the source of serializeSet(Set> set)
public static byte[] serializeSet(Set<?> set)
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.Closeable; import java.io.ObjectOutputStream; import java.util.Set; public class Main { public static byte[] serializeSet(Set<?> set) { if (set.isEmpty()) { return null; }// w w w.j a v a 2 s . co m ObjectOutputStream oos = null; ByteArrayOutputStream baos = null; byte[] bytes = null; try { baos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(baos); for (Object obj : set) { oos.writeObject(obj); } bytes = baos.toByteArray(); } catch (Exception e) { e.printStackTrace(); } finally { close(oos); close(baos); } return bytes; } public static void close(Closeable closeable) { if (closeable != null) { try { closeable.close(); } catch (Exception e) { e.printStackTrace(); } } } }