Set
provides an unordered data structure, and duplicate elements are not allowed. Some classes implemented by the Set
interface are java.util.HashSet
, java.util.LinkedHashSet
, and so on. For this recipe, we will use the java.util.HashSet
class, which implements the java.util.Set
interface. The only difference between List
and Set
is that Set
doesn't allow duplicate values. For example, in our previous example, we added the e-mail address with emailaddress3@provider3.com
twice, and hibernate will allow us to do this. But in case of Set
, you cannot add a duplicate value. Let's take a look at how to achieve this.
Argentina
Australia
Austria
Belgium
Brazil
Bulgaria
Canada
Chile
Colombia
Cyprus
Czechia
Denmark
Ecuador
Egypt
Estonia
Finland
France
Germany
Great Britain
Greece
Hungary
India
Indonesia
Ireland
Italy
Japan
Latvia
Lithuania
Luxembourg
Malaysia
Malta
Mexico
Netherlands
New Zealand
Norway
Philippines
Poland
Portugal
Romania
Russia
Singapore
Slovakia
Slovenia
South Africa
South Korea
Spain
Sweden
Switzerland
Taiwan
Thailand
Turkey
Ukraine
United States