title: What can I store a single element in a Collection?
body: <p>I've got a DTO object used to get data from my server. It can be used for one or several elements. This DTO encapsulate a <code>Collection</code> containing the data.</p>
  
  <p>When my DTO brings me only one element, how should I store it?</p>
  
  <p>Sample code:</p>
  
  <pre><code>public class DataDTO implements Serializable
  {
      private Collection&lt;Data&gt; data;
  
      public DataDTO()
      {
      }
  
      public Collection&lt;Data&gt; getData()
      {
          return data;
      }
  
  
      public void setData(Collection&lt;Data&gt; data)
      {
          this.data = data;
      }
  
  
      public void setData(Data singleData)
      {
          // At this time I use an ArrayList initialized with a capacity of 1
          this.data = new ArrayList&lt;Data&gt;(1);
          this.data.add(singleData);
      }
  }
  </code></pre>