J
Jean Lutrin
Hi all,
I'd like to sort through a huge list of Strings and keep only
unique Strings. There can not be in my result two String a and b for
which : a.equals(b) == true.
So my first idea was to simply put each String in a HashMap, which
would automatically discard duplicates (and this is really easy to
implement).
However, nothing garantees that two Strings being equals have the same
object reference (which is why we have to use .equals() btw !?).
So what is the simplest way I could use to do this ? (I'd like to do this
with a sort of hashtable/map/set whatever to have an O(1) complexity).
Do I have to make my own "string" class with a special hashcode method ?
Any help appreciated (btw, this is not for homework, I'm way too old for that),
Jean
I'd like to sort through a huge list of Strings and keep only
unique Strings. There can not be in my result two String a and b for
which : a.equals(b) == true.
So my first idea was to simply put each String in a HashMap, which
would automatically discard duplicates (and this is really easy to
implement).
However, nothing garantees that two Strings being equals have the same
object reference (which is why we have to use .equals() btw !?).
So what is the simplest way I could use to do this ? (I'd like to do this
with a sort of hashtable/map/set whatever to have an O(1) complexity).
Do I have to make my own "string" class with a special hashcode method ?
Any help appreciated (btw, this is not for homework, I'm way too old for that),
Jean