Originally Posted by
Perd1t1on
thanks, after playing around with it I realized that a hashset can only add members and check if a member is inside the hashset. So it's limited but fast. I'm guessing you would convert it to an array after you have established what it contains as opposed to making an array that could have empty elements. It's advantage over a list is that it is much faster, but cannot retrieve indexes. Is this all right?
You can iterate over the set by retrieving its iterator:
Set<String> mySet = new HashSet<String>();
....
Iterator<String> it = mySet.iterator():
while (it.hasNext()){
String s = it.next();
}
However based upon how the storage works, the order is not guaranteed - eg don't expect this method to iterate over the contents in the order the objects were placed in the set (a LinkedHashSet can accomplish this however).