title: What's a proper way to pass ArrayList<int[]>[] in an intent?
body: <p>I have this collection</p>
  
  <pre><code>ArrayList&lt;int[]&gt;[] myList;
  </code></pre>
  
  <p>that is, an array of ArrayLists of integer arrays. I am trying to pass it in an intent.</p>
  
  <pre><code>intent.putExtra(getString(R.string.app_name) + ".myList", myList);
  </code></pre>
  
  <p>In the new activity I try to get the extra as:</p>
  
  <pre><code>ArrayList&lt;int[]&gt;[] myList;
  
  Intent intent = getIntent();
  myList = (ArrayList&lt;int[]&gt;[]) intent.getSerializableExtra(getString(R.string.app_name) + ".myList");
  </code></pre>
  
  <p>However I am getting a class cast exception in that line.</p>
  
  <pre><code>Caused by: java.lang.ClassCastException: java.lang.Object[] cannot be cast to java.util.ArrayList[]
  </code></pre>
  
  <p>As they contain arrays of primitive types and ArrayList is a serializable class itself, I am at a loss as to why this isn't working or what would be a better way to proceed.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>It appears that one can't just cast Object[] to CustomClass[]</p>
  
  <p>Check:</p>
  
  <p><a href="https://stackoverflow.com/questions/395030/quick-java-question-casting-an-array-of-objects-into-an-array-of-my-intended-cl">Quick Java question: Casting an array of Objects into an array of my intended class</a></p>
  
  <p><a href="https://stackoverflow.com/questions/1115230/casting-object-array-to-integer-array-error">casting Object array to Integer array error</a></p>
  
  <p>So one solution would be</p>
  
  <pre><code>Object[] tmp = (Object[]) intent.getSerializableExtra(getString(R.string.app_name) + ".myList");
  myList = Arrays.copyOf(tmp, tmp.length, ArrayList[].class);
  </code></pre>
  
  <p>Or alternatively, one can pass and retrieve an ArrayList</p>
  
  <pre><code>// Calling Activity
  ArrayList&lt;ArrayList&lt;int[]&gt;&gt; myIntentList = new ArrayList(Arrays.asList(myList));
  intent.putExtra(getString(R.string.app_name) + ".myList", myIntentList);
  
  // Called Activity
  ArrayList&lt;ArrayList&lt;int[]&gt;&gt; myIntentList;
  
  myIntentList = ArrayList&lt;ArrayList&lt;int[]&gt;&gt; intent.getSerializableExtra(getString(R.string.app_name) + ".myList");
  </code></pre>