title: Deep copy of a list with custom objects in java
body: <p>I have a List with custom objects. I want to create a deep copy of that List.
  Here is the class of the custom Object:</p>
  
  <pre><code>public class MyMemo {
      private List&lt;Uri&gt; imageUriList;
      private String commentText;
  
      public MyMemo(){
          imageUriList = new ArrayList&lt;&gt;();
      }
  
      public List&lt;Uri&gt; getImageUriList() {
          return imageUriList;
      }
  
      public void setImageUriList(List&lt;Uri&gt; imageUriList) {
          this.imageUriList = imageUriList;
      }
  
      public String getCommentText() {
          return commentText;
      }
  
      public void setCommentText(String commentText) {
          this.commentText = commentText;
      }
  }
  </code></pre>
  
  <p>Now I have below situation:</p>
  
  <pre><code>List&lt;MyMemo&gt; parentList = new ArrayList&lt;&gt;();
  List&lt;MyMemo&gt; copyList = new ArrayList&lt;&gt;(parentList);
  parentList.get(currentMemoPosition).getImageUriList().removeAll(someOtherList.getImageUriList());
  Log.e(TAG,"Total List: "+parentList.get(currentMemoPosition).getImageUriList().size()+" "+copyList.get(currentMemoPosition).getImageUriList().size());
  </code></pre>
  
  <p>But if I make any change to the <code>parentList</code> i.e either <code>delete</code> an item from it or <code>add</code> new item to it. <code>copyList</code> is also effected. How can I make sure copyList is not referring the same memory address.</p>
  
  <p>Update:</p>
  
  <p>As suggested to use <code>clone()</code>. But problem is I have a list in my custom object. How can I <code>clone()</code> them?</p>