Note that this new toString() implementation and the enumeration
returned do not present the characters in ascending Unicode order like
the original version did; the hashtable will enumerate through its
elements in a totally unpredictable (implementation dependent) manner.
If this exact ordering was part of the public contract of the
WhichChars class, then this new version would have to make sure to
return the characters in the proper order as well.


import java.util.*;

public class WhichChars {
    private Hashtable used = new Hashtable();

    public WhichChars(String str) {
	for (int i = 0; i < str.length(); i++) {
	    Character chObj = new Character(str.charAt(i));
	    used.put(chObj, chObj);	// value not important, use char object
	}
    }

    public String toString() {
	StringBuffer desc = new StringBuffer(2 + used.size());

	desc.append('[');
	Enumeration enum = used.keys();
	while (enum.hasMoreElements())
	    desc.append((Character)enum.nextElement());
	desc.append(']');

	return desc.toString();
    }

    public Enumeration characters() {
	return used.keys();
    }
}
