For Programmers: Free Programming Magazines  


Home > Archive > Java Help > October 2004 > Two dimensional hash









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Two dimensional hash
Hongyu Zhang

2004-10-28, 8:57 pm

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

2004-10-28, 8:57 pm

Hongyu Zhang wrote:

> 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/tuto...ultiarrays.html

You should also read up on collections here:

http://java.sun.com/docs/books/tutorial/collections/

HTH,
Carl.
Thomas Weidenfeller

2004-10-29, 8:57 am

Hongyu Zhang wrote:
> 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

2004-10-29, 8:57 pm

Both methods that you suggested are good enough for me. Thanks very much, Thomas!

Thomas Weidenfeller <nobody@ericsson.invalid> wrote in message news:<clsstv$3q6$1@newstree.wise.edt.ericsson.se>...
> Hongyu Zhang wrote:
>
> 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

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com