Using StringBuilder will never work, as one instance is NOT equal to another instance of StringBuilder
Correct your code for something like this
Map<String, String> map = new HashMap<String, String>();
map.put(sb.toString(), "a");
map.put(sb1.toString(), "b");
but since this is a map view, if sb.toString () and sb1.toString () are equal, as in your example, the value will be overridden
Thus, the result with corrections to your code
----Inside Main method---- mapValue{sb=b}
Expected value a, coming also => b
Expected value b, coming also => b
Expected value a, not coming => b
----Inside receiveMap method mapValue{sb=b}
Expected value a, not coming => b
Expected value b, not coming => b
Expected value a, coming also => b
Expected value b, coming also => b
source
share