title: Converting all objects in arraylist to byte array in java
body: <p>I have an ArrayList with data that is my own custom object and I need to convert all of them into a byte array. I am able to convert the object to a byte array by serializing it but I need all the objects to be serialized into one array. </p>
  
  <pre><code>ArrayList&lt;MyObject&gt; myArrayList = new ArrayList&lt;MyObject&gt;();
  // Getting a list of objects of database (any unknown number)
  for(int counter = 0; counter &lt; myObj.size(); counter++) {
      byte[] myData = serialize(myObj.get(counter));
  }
  </code></pre>
  
  <p>Now how do I go about doing this for multiple objects as I do not know the length to initialize by byte array buffer?</p>