title: Writing ArrayList object in a file
body: <p>My objective is to create a function which will write an <em>Arraylist</em> of <strong>Account</strong>(my class) type in a file. I have written the following code but the <em>ArrayList</em> <strong>myList</strong> is only adding the details specified in the second run of the loop twice..Plus for the second run it just skips the <strong>name</strong> field entry to <strong>ac</strong>.</p>
  
  <pre><code>public void builIT(){
      Scanner sc = new Scanner(System.in);
      ArrayList&lt;Account&gt; myList = new ArrayList&lt;&gt;();
      Account a = new Account();
      String name = null;
      String ac = null;
      String phone = null;
      String email = null;
      String password = null;
      double balance = 0;
      try{
          FileOutputStream fout = new FileOutputStream("c:\\Users\\srawa\\Desktop\\thisisit");
          ObjectOutputStream oos = new ObjectOutputStream(fout);
          for(int i=0;i&lt;2;i++){                
              System.out.print("Name:");
                  name=sc.nextLine();
              System.out.print("ACNO:");
                  ac=sc.nextLine();
              System.out.print("Phone:");
                  phone=sc.nextLine();
              System.out.print("Email:");
                  email=sc.nextLine();
              System.out.print("Password:");
                  password=sc.nextLine();
              System.out.print("Balance:");
                  balance=sc.nextDouble();
              a.set(name,ac,phone,email,password,balance);
              System.out.println(a);
              myList.add(a);               
              System.out.println(myList);
          }
  
          oos.writeObject(myList);
          oos.close();
      }catch(Exception e){
          e.printStackTrace();
      }
      }
  </code></pre>
  
  <p>Please help. Thank you.
  P.S.- I'm new to Stackoverflow. </p>