I ' musingahashmapandihaven ' tbeenabletogetastraightansweronhowtheget () methodworksinthecaseofcollisions。
let ' s say n1 objectsgetplacedinthesamekey.aretheystoredinalinkedlist? aretheyoverwrittensothatonlythelastobjectplacedinthatkeyexiststhereanymore? aretheyusingsomeothercollisionmethod?
If they are placed in a LinkedList,isthereawaytoretrievethatentirelist? If not,istheresomeotherbuiltinmapforjavainwhichicandothis?
For my purposes,separate chaining would be ideal,as if there are collisions,ineedtobeabletolookthroughthelistandgetinformationationabonabouboution
Thanks for all your help!
解决方案
aretheyoverwrittensothatonlythelastobjectplacedinthatkeyexiststhereanymore?
Yes,assuming you ' reputtingmultiplevalueswiththesamekey (accordingtoobject.equals,not Object.hashCode.) that ' specod
ifthemappreviouslycontainedamappingforthekey,theoldvalueisreplacedbythespecifiedvalue。
ifyouwanttomapakeytomultiplevalues,you ' reprobablybetteroffusingsomethinglikeguava ' slist multimap, arraylistmultimapinspeecification whichmapskeystolistsofvalues.(disclosure : icontributetoguava.) if you can ' toleraterateate