StringBuffer and StringBuilder do not override equals or hashCode. That means that equals uses only ==. In other words, your two keys are different, and that's why the map has 2 elements.
You try to get it using "1". Even if StringBuffer would have overridden equals to check the contents, you are trying to get the value using a
String - an object from a completely different, incompatible class.
As for the get method, assuming the key is not null:
The hash method translates the key's actual hashCode, to "[defend] against poor quality hash functions" (quoted from its Javadoc). The indexFor method translates that in the
bucket number. A bucket is a collection of objects which are grouped together. For HashMap that's based on the hash codes. The "table" field is the actual collection of buckets, as an Entry[] (with Entry being an inner class). This Entry class is actually a form of singly linked list, representing the bucket.
The for-loop checks each Entry to see if the key matches. If it does, that's the right Entry and its value is returned. If not the next Entry is checked until there are no more, in which case null is returned.