I’m having an issue where I can’t get values to go into a certain spot of my array lists. I have user input that successfully stores the Strings into variables but I don’t know how to put them into a specific cell of the array.
Code:
public void newAccount() {
firstName = JOptionPane.showInputDialog("What's your first name?");
nLastName = JOptionPane.showInputDialog("What's your last name?");
nAddress = JOptionPane.showInputDialog("What's your current address?");
nCity= JOptionPane.showInputDialog("What's your current city?");
nState = JOptionPane.showInputDialog("What's your current State?");
nZipCode = JOptionPane.showInputDialog("What's your current Zip Code?");
account.add( accountNumber, firstName);
account.add( accountNumber, nLastName);
account.add( accountNumber, nAddress);
account.add( accountNumber, nCity);
account.add( accountNumber, nState);
account.add(accountNumber, nZipCode);
}
If the variable account is an Arraylist then you’re using it wrongly. You are adding only the ZipCode to the arraylist at position account number.
You should create an account object in which the first and last names, zip codes etc go into.
Then put this account object into the Arraylist. That way you’ll have an Arraylist populated with account objects.