Reputation: 15734
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
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