Find an object with a data member with a unique value in Java?
<p>I'm doing a Java task that is like a simple bank system with Customer objects and SavingsAccount. I store all Customer objects in an arraylist and I was also planning to do the same with the SavingsAccount objects, but that is perhaps not necessary. Each SavingsAccount has a data member called accountNumber that is unique. </p>

<p>The SavingsAccount also include data members lika accountBalance. So my question is how do I reach a SavingsAccount that has the accountNumber equal to "1002" (For some reason I have them as Strings) and then be able to set or get values from data member, like accountBalance with setAccountBalance? Help is preciated! Thanks!</p>

<p>I create the account object</p>

<pre><code>SavingsAccount account = new SavingsAccount(inAccount);
</code></pre>

<p>The class SavingsAccount:</p>

<pre><code>class SavingsAccount {

// data members
private String accountType;
private String accountNumber;
private double accountInterestRate;
private int accountBalance;

// constructor
public SavingsAccount(String inNumber){
    accountType = "Saving";
    accountNumber = inNumber;
    accountInterestRate = 0.5;
    accountBalance = 0;
}

// get account number
public String getAccountNumber() {
    return accountNumber;
}

// get account balance
public int getAccountBalance() {
    return accountBalance;
}

// get interest rate
public double getAccountInterestRate(){
    return accountInterestRate;
}

    // set new value to balance
    public void setAccountBalance(int inMoney){
    accountBalance = accountBalance + inMoney;
    }

}
</code></pre>

<p>EDIT:</p>

<p>Since I'm learning Java, I prefer a solution that is not to complicated to use right now. I know how to use arraylist, but I haven't reach to the hashmap yet, and was hoping for a simplier, but perhaps not the best, solution for now? Isn't there a way to reach objects without "collecting" them in arraylist or hashmap?</p>
