Re: Is there a Class like HashMap, but...

From: Scott Ellsworth (scott_at_alodar.com)
Date: 12/30/04


Date: Thu, 30 Dec 2004 14:35:15 -0800

In article <33gqmqF3vpia3U1@individual.net>,
 ByteCoder <ByteCoder@127.0.0.1> wrote:

> ByteCoder wrote:
> > ByteCoder wrote:
> >
> >> Is there a Class like HashMap, but which only stores the key.
> >>
> >> Basicly, I want a Class which adds unique objects to it, but which
> >> overwrites non-unique objects.
> >>
> >> TIA,
> >
> >
> > I finally found it, it's the HashSet. :)
> >
>
> One more thing: Does the HashSet has some sort of get method, so that I
> don't have to use an Iterator if I just want to get one object?
> Or wouldn't that be a problem if my HashSet has about 200 elements?

If you want to see whether a given object is in the set, use contains().
If you want to get all the objects in a set, use iterator, and if you
just want "any old object", use iterator().next().

Scott



Relevant Pages

  • Re: Is there a Class like HashMap, but...
    ... Does the HashSet has some sort of get method, ... There should be minimal cost in creating an Iterator, ...
    (comp.lang.java.programmer)
  • Re: HashSet method to retrieve set elements
    ... Alex Hunsley wrote: ... >> I would like to know besides using iterator method, ... >> method to retrieve previous inserted HashSet elements? ... essentally creating a duplicate of the HashSet in array form which is ...
    (comp.lang.java.help)
  • Re: Iteration over sets
    ... >> iterator to treat these new elements as if they have not been seen so ... doing so seems to guarantee that concurrent modification ... > returned by a HashSet does not guarantee any specific order in which it ... > HashSet and write your own ListIterator implementation. ...
    (comp.lang.java.programmer)
  • Re: Is there a Class like HashMap, but...
    ... > ByteCoder wrote: ... >> Is there a Class like HashMap, but which only stores the key. ... >> Basicly, I want a Class which adds unique objects to it, but which ... Does the HashSet has some sort of get method, ...
    (comp.lang.java.programmer)
  • Re: Iteration over sets
    ... doing so seems to guarantee that concurrent modification ... The standard HashSet implementation and the Iterator returned by it ... HashSet and write your own ListIterator implementation. ...
    (comp.lang.java.programmer)