Forums > Java

ugly, but how do I do this?


jbm
October 17, 2006 | 7:30 pm

I have an Atom[] in a TreeMap, which is also in a TreeMap!! I told you it was ugly…

Is there a one-liner to change a single value at an index in the Atom[]?

I understand that:

map1.get(key1).get(key2)

can pull out my Atom[], but can I get the Atom at a given index as well? I tried:

map1.get(key1).get(key2)[1] = something-that’s-an-Atom;

But that didn’t work… it’s getting an object when it wants an array. I understand it needs to be cast somewhere, but where?

J.


October 17, 2006 | 8:17 pm

> map1.get(key1).get(key2)[1] = something-that’s-an-Atom;
>
> But that didn’t work… it’s getting an object when it wants an array. I understand it needs to be cast somewhere, but where?

try

((Atom [])(map1.get(key1).get(key2)))[1]

Ben



jbm
October 17, 2006 | 9:51 pm

geez… I don’t know how long it would have taken me to figure that out, but you know what happens when you put a monkey at a macbook…

thanks, Ben.

J.


Viewing 3 posts - 1 through 3 (of 3 total)