>>The String should be different each time and then added to the
>>xhd HashSet. However when I do this I only get the last string passed to
[quoted text clipped - 7 lines]
>I can't think of any plausible scenario where you would want to
>concatenate keys.
Sorry I didn't explain that properly. I shouldn't have said "they are
not appended to the previous String", what I meant was they are not
appended to the Set. I got this working by simply adding it within my
superclass, rather than calling the subclass I was using. Not quite sure
why it wouldn't work, possibly because there are several loops within
loops which might have caused problems. Anyway, I have another question,
which is how do I output the Set a string at a time? At the moment
printing xhd just prints the whole Set. Eventually I want to compare
them (using compareTo I'd guess), but I'd like to know how to Iterate
through them properly an element at a time and then print the result. Do
I have to override toString to do this or is it relatively
straightforward?

Signature
Jeffrey Spoon
Andrew Harker - 20 Mar 2004 15:49 GMT
> loops which might have caused problems. Anyway, I have another question,
> which is how do I output the Set a string at a time? At the moment
> printing xhd just prints the whole Set. Eventually I want to compare
> them (using compareTo I'd guess), but I'd like to know how to Iterate
> through them properly an element at a time and then print the result. Do
> I have to override toString to do this or is it relatively straightforward?
Use the Object returned by iter.next() which you
throw away in the code you originally posted, ie replace
xhd by iter.next()
Iterator iter = xhd.iterator();
while(iter.hasNext()) {
System.out.println("> " + iter.next() + " <");
}
Suggest you look at api docs
<http://java.sun.com/j2se/1.4.2/docs/api/index.html>
<http://java.sun.com/j2se/1.4.2/docs/api/java/util/Iterator.html>
and tutorials
<http://java.sun.com/docs/books/tutorial/collections/index.html>
<http://java.sun.com/docs/books/tutorial/collections/interfaces/collection.html>
cheers

Signature
Andrew
Jeffrey Spoon - 20 Mar 2004 16:22 GMT
>> loops which might have caused problems. Anyway, I have another
>>question, which is how do I output the Set a string at a time? At the
[quoted text clipped - 12 lines]
> System.out.println("> " + iter.next() + " <");
> }
Ah, that's it. Thanks. I have looked at those other links, believe it or
not.

Signature
Jeffrey Spoon