0

I'm trying to put two separate objects in my Hashmap but when I do it just puts the same object in multiple times.

So I have a Hashmap HashMap<Integer, Account> account_map = new HashMap<>(); and a method to make accounts that is

public static Account makeAccount(int id, String handle) {
        Account output_account
                = new Account(id, handle," ", 0) ;
        return output_account;

I then go to put two accounts in my Hashmap by doing

        Account output1 = makeAccount(1, "Hat");
        Account output2 = makeAccount(2, "Coat");
        //output1 = makeAccount(1, "Hat");
        account_map.put(1, output1);
        //output2 = makeAccount(2, "Coat");
        account_map.put(2, output2);
        System.out.println(account_map);

but that just returns the following

{1=Account ID: 2.
 Account Handle: Coat.
 Account Description:  .
 Account Popularity: 0.
This is the Most Popular Account: false, 2=Account ID: 2.
 Account Handle: Coat.
 Account Description:  .
 Account Popularity: 0.
This is the Most Popular Account: false}

With output2 in both 1 and 2 rather than output1 in 1 and output2. Anyone able to help?

0 Answers0