I was wondering if its possible to store an object into a arraylist where the user wants it. For my program its storing the users data into a cell of their choice via an “account number” but every time I type in a new account number it says that the array isn’t big enough basically. Here is my code. If anyone could help that would be appreciated.
ArrayList <Account> account = new ArrayList<Account>();
int accountNumber;
String nCity;
String nState;
String nZipCode;
String nLastName;
String nAddress;
String firstName;
String nAccount;
public void newAccount()
{
Account a = new Account();
a.firstName = JOptionPane.showInputDialog("What's your first name?");
a.nLastName = JOptionPane.showInputDialog("What's your last name?");
a.nAddress = JOptionPane.showInputDialog("What's your current address?");
a.nCity= JOptionPane.showInputDialog("What's your current city?");
a.nState = JOptionPane.showInputDialog("What's your current State?");
a.nZipCode = JOptionPane.showInputDialog("What's your current Zip Code?");
String num = JOptionPane.showInputDialog("What do you want your account number to be?");
accountNumber = Integer.parseInt(num);
account.add(accountNumber, a);
Use a
HashMapand use the account number as the key