Dear all,
Anyone knows an easy way to use a two dimensional hash in Java? For
example, in Perl, it can be used like $foo{$bar1}{$bar2}.
Thanks!
Carl - 29 Oct 2004 01:07 GMT
> Dear all,
>
> Anyone knows an easy way to use a two dimensional hash in Java? For
> example, in Perl, it can be used like $foo{$bar1}{$bar2}.
>
> Thanks!
What exactly are you trying to store, and how do you intend to access it?
For starters, you may be interested in reading about multi-dimensional
arrays:
http://java.sun.com/docs/books/tutorial/java/data/multiarrays.html
You should also read up on collections here:
http://java.sun.com/docs/books/tutorial/collections/
HTH,
Carl.
Thomas Weidenfeller - 29 Oct 2004 08:57 GMT
> Dear all,
>
> Anyone knows an easy way to use a two dimensional hash in Java?
Yes, the obvious ones:
* Use Maps of Maps - inefficient
or
* Combine the two keys into one object, using that as a key in a Map.
Which is the way multidimensional hashs are usually implemented.
/Thomas
Hongyu Zhang - 29 Oct 2004 23:47 GMT
Both methods that you suggested are good enough for me. Thanks very much, Thomas!
> > Dear all,
> >
[quoted text clipped - 10 lines]
>
> /Thomas