shalika range
shalika range

Reputation: 23

arrayList for loop in to a hashMap size shows is correct but elements are one less. no duplicate key used

Map coreAccounts = new HashMap<>();

        List<Account> accounts = coreBankUserDetails.getAccounts();
        //

        for(int i=0;i<accounts.size();i++){
            Account model = accounts.get(i);

            coreAccounts.put(model.getAccountNumber(),model);
        }

image shows size as 5 but only 4 elements in the table

Upvotes: 1

Views: 81

Answers (2)

DevMS
DevMS

Reputation: 72

You have to check one of accounts has null value. because the result says "Not showing null elements" and your result size is 5 and table only shows 4 element.

Upvotes: 0

vivekdubey
vivekdubey

Reputation: 510

if model.getAccountNumber() is Wrapper class ideally it should not be happened,there is only one possibility if HashCode is overriden and for 2 element hascode are same two object are equals then it is possible.So you should check hascode and equals method in Account class.

Upvotes: 1

Related Questions