TheLettuceMaster
TheLettuceMaster

Reputation: 15734

Size of HashMap not increasing

I go through a loop three times and call this method each time:

// class variable
private HashMap<String, ffMotorskillsSession> tempMap;


tempMap = new HashMap<String, ffMotorskillsSession>();
for loop {    

     addMotorskillsSession(session);

}

private void addMotorskillsSession(ffMotorskillsSession pSession) {

    StringBuilder sb = new StringBuilder();
    sb.append(pSession.period).append(":").append(pSession.section)
            .append(":").append(pSession.class_name).append(":")
            .append(pSession.semester).append(":").append(pSession.grade);
    tempMap.put(sb.toString(), pSession);
    Log.d("Size: ", String.valueOf(tempMap.size()));
}

Everytime I Log the size each time it passes thru it stays at one.

Can anyone see why?

Upvotes: 0

Views: 940

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500495

A Map stores key/value pairs, with only one value per key. So if you're calling put with the same key multiple times, then it will correctly stick to the same size, only having a single entry for that key.

Upvotes: 3

Related Questions