HashSet extends AbstractSet and implements the Set interface. It creates a collection that uses a hash table for storage.
A hash table stores information by using a mechanism called hashing. In hashing, the informational content of a key is used to determine a unique value, called its hash code.
The hash code is then used as the index at which the data associated with the key is stored. The transformation of the key into its hash code is performed automatically.
The HashSet class supports four constructors. The first form constructs a default hash set:
HashSet()
The following constructor form initializes the hash set by using the elements of c.
HashSet(Collection c)
The following constructor form initializes the capacity of the hash set to capacity.
The capacity grows automatically as elements are added to the Hash.
HashSet(int capacity)
The fourth form initializes both the capacity and the fill ratio (also called load capacity) of the hash set from its arguments:
HashSet(int capacity,float fillRatio)
If you have person class , you want to get unique person name and make a array then HashSet help you.
boolean add(Object o)
Adds the specified element to this set if it is not already present.
Set<String> titles = new HashSet<String>();
for (int i = 0; i < personList.size(); i++) {
if(titles.add(personList.get(i).getName()))
Here you get only the unique person name . so give you code , What you want.
}
<script type=”text/javascript”>
( function() {
if (window.CHITIKA === undefined) { window.CHITIKA = { ‘units’ : [] }; };
var unit = {“publisher”:”solutionexplorer”,”width”:550,”height”:250,”sid”:”Chitika Default”};
var placement_id = window.CHITIKA.units.length;
window.CHITIKA.units.push(unit);
document.write(‘<div id=”chitikaAdBlock-‘ + placement_id + ‘”></div>’);
var s = document.createElement(‘script’);
s.type = ‘text/javascript’;
s.src = ‘//cdn.chitika.net/getads.js’;
try { document.getElementsByTagName(‘head’)[0].appendChild(s); } catch(e) { document.write(s.outerHTML); }
}());
</script>