Sangram Anand
Sangram Anand

Reputation: 10844

Elements missing when added to Set

StringUtils.split(topic.getFirstorgroup(), ",") 

returns a list of 47 elements.

apiFormatBooleanTopic.setTopics(Sets.newHashSet(StringUtils.split(topics.getFirstorgroup(), ",") );

But when am trying to add them in the method method which accepts set, the value that are added to the object are only 28, i wonder why the remaining are missing.

Upvotes: 0

Views: 196

Answers (1)

Kai
Kai

Reputation: 39631

A Set can not hold duplicated entries. When you add an entry which is already contained the old one is replaced. (Think of it as keys of a Map). It is considered as "contained" if equals() of that object returns true.

Upvotes: 6

Related Questions