H
Harald Kirsch
My applications does a lot of text crunching, filtering
information out of the text. For reasons of efficiency
all the text handling is done in StringBuffer objects.
When the application finds something interesting, it wants
to store it in a Hashtable with the text to be used as a
key still in the StringBuffer.
In order to test whether the key is already known to the Hashtable
I currently create a String object from the StringBuffer. But
most of the time the key happens to be already known to the
Hashtable and the String created is immediately thrown away again.
How can I use a reusable object, e.g. a StringBuffer, as a key to
the Hashtable such that hashing is performed according .equals()
instead of according to object identity.
I know that it will be a disaster if I change a stored object later,
but maybe someone knows a clean way to get around the superflous
creation of a String object.
Thanks,
Harald.
information out of the text. For reasons of efficiency
all the text handling is done in StringBuffer objects.
When the application finds something interesting, it wants
to store it in a Hashtable with the text to be used as a
key still in the StringBuffer.
In order to test whether the key is already known to the Hashtable
I currently create a String object from the StringBuffer. But
most of the time the key happens to be already known to the
Hashtable and the String created is immediately thrown away again.
How can I use a reusable object, e.g. a StringBuffer, as a key to
the Hashtable such that hashing is performed according .equals()
instead of according to object identity.
I know that it will be a disaster if I change a stored object later,
but maybe someone knows a clean way to get around the superflous
creation of a String object.
Thanks,
Harald.