Well, your treeset key values are "A1","B1","A1","A2". Even though you are not overriding equals and hashcode still the default hashcode for "A1" will be same and hence the treeset will consider this key as duplicate key so you will not be able to enter "A1","B2"