public static void main(String[] args) {
HashSet set = new HashSet();
set.add(new StringBuffer(\"abc\"));
set.add(new StringBuffer(\"abc\"));
set.a
Did it occur to you to see the equals() method (or the lack of it) in the StringBuffer? There lies the answer for you.
A Set or for that matter any hash based collection depends on the contract exposed by the equals() and hashcode() method on the Object for their behavior characteristic.
In your case since StringBuffer doesn't override these methods each StringBuffer instance that you create is different i.e new StringBuffer("abc") == new StringBuffer("abc") will return false.
I am curious as to why would someone add StringBuffer to a set.