title: Reading ArrayList as object from file?
body: <p>Alright, so I have done the following:</p>
  
  <ol>
  <li><p>I've added objects to an ArrayList and written the whole list as an object to a file.</p></li>
  <li><p>The problem is when trying to read them back as a whole. I get the following error:</p></li>
  </ol>
  
  <p><strong>Exception in thread "main" java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList
      at persoana.Persoana.main(Student.java:64)</strong></p>
  
  <p>Here's my code: (Everything is in a try catch so nothing to worry about that)</p>
  
  <p><strong>Writing</strong></p>
  
  <pre><code>Student st1 = new Student("gigi","prenume","baiat","cti");
          Student st2= new Student("borcan","numegfhfh","baiat cu ceva","22c21");
  
          List &lt;Student&gt; studenti = new ArrayList&lt;Student&gt;();
          studenti = Arrays.asList(st1,st2);
  
  FileOutputStream  fos = new FileOutputStream("t.ser");
              ObjectOutputStream oos = new ObjectOutputStream(fos);
  
              oos.writeObject(studenti);
              oos.close();
  </code></pre>
  
  <p><strong>Reading</strong></p>
  
  <pre><code>FileInputStream fis = new FileInputStream("t.ser");
               ObjectInputStream ois = new ObjectInputStream(fis);
  
               ArrayList &lt;Student&gt; ds;
  
               ds = (ArrayList &lt;Student&gt;)ois.readObject(); 
  
               ois.close();
  </code></pre>
  
  <p>The problem occurs at this line:</p>
  
  <pre><code>ds = (ArrayList &lt;Student&gt;)ois.readObject();
  </code></pre>