title: Creating an immutable list from an existing list using streams
body: <p>There is a list of <code>Person</code> objects. </p>
  
  <p><code>List&lt;Person&gt; persons = generatePersons();</code></p>
  
  <p>An unmodifiableList is created with it. </p>
  
  <p><code>List&lt;Person&gt; unmodifiableList = Collections.unmodifiableList(persons);</code></p>
  
  <p>I understand that <code>unmodifiableList</code> doesn't support add/remove/set operations. At the same time it is not immutable since it has a reference to an existing modifiable list <code>persons</code> and whenever changes are made to the <code>persons</code> list, the changes are reflected in <code>unmodifiableList</code> too. </p>
  
  <p>An immutable list is created this way. </p>
  
  <p><code>List&lt;Person&gt; immutableList = Collections.unmodifiableList(new ArrayList&lt;&gt;(persons));</code></p>
  
  <p>This creates an immutable list since a conversion constructor is being used. No add/remove/set ops can be performed on <code>immutableList</code> nor any change in the original list <code>persons</code> would reflect in <code>immutableList</code>. 
  Let's make an assumption that <code>Person</code> objects are immutable too.  </p>
  
  <p>Now, I want to create these two lists using streams. </p>
  
  <p>The first one, I have created using: </p>
  
  <p><code>List&lt;Person&gt; unmodifiablePersons = persons.stream()
  .collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList));</code></p>
  
  <p>I am lost at creating equivalent of immutableList through streams. </p>
  
  <p>How can I do that? </p>
  
  <p><strong>Edit:</strong> </p>
  
  <p>I added a new <code>Person</code> object to the original list <code>persons</code> and printed the size of <code>persons</code> list and <code>unmodifiablePersons</code>. Both give me the same size. 
  So, changes are being reflected to <code>unmodifiablePersons</code>and hence it is not immutable yet. Am I missing something here?</p>
  
  <p><strong>Edit 2</strong></p>
  
  <p>Silly. Should have gone through the docs. <code>unmodifiablePersons</code> is indeed an immutable list. Also, the new <code>Person</code> object was added before the <code>unmodifiablePersons</code> was created and hence the above observation. Super silly. </p>