Q:

Multi-layered Hash in Java

In Perl if I want to have a multi-layered hash, I would write:
$hash_ref->{'key1'}->{'key2'}='value';

Where 'key1' might be a person's name, 'key2' might be "Savings Account" (vs. "Checking Account") and 'value' might be the amount of money in the account.
Is there an equivalent to this in Java, i.e. access values via hash references? What's the syntax like for this? Any examples or other resource references would be greatly appreciated. Thanks! 

A:

In Java, we use objects. We would have a Person object, with a name property of type String, and a savingsAccount of type Account. This Account object would have a value property, of type BigDecimal.
Java is an OO language. It's not Perl. You should use Java idioms in Java, and not Perl idioms.

A:

You can have a Map<Map<..>>, where you'll be able to call map.get("key1").get("key2")
But note that Java is a statically-typed, object-oriented language. So you'd better creat classes: Person, SavingsAccount, and a Person has a field private SavingsAccount savingsAcount. Then you'll be able to do a compile-time safe: map.get("John").getSavingsAccount()

