danillosl
danillosl

Reputation: 519

How to persist a hashtable

I have to persist a hash table which respect the following order : key, value = father, children.

I tried some approaches like

for(Acao pAcao : hashtableAcaoDotacao.keySet()){
    for(Dotacao pDotacao : hashtableAcaoDotacao.get(pAcao)){

    }
}

Where Acao is the key and the value is a ArrayList, but for some reason the hashtable can't find the key pAcao.

Upvotes: 1

Views: 138

Answers (1)

neo
neo

Reputation: 1074

Whenever you want to use any customize class as key such as

Acao pAcao

Acao class must implement hashCode and equals methods. Besides that its good practice to use key class as immutable class. It's preferred to used class such as String/Integer to use as key class.

Similar thread - Setting own class as key in java Hashmap

Upvotes: 1

Related Questions