Java - Maps inside a Map or Key Object? -
hi having 3 attributes (string) needed identify object.
what improve solution:
using key object post pierre , joachim sauer this:
public class mykey{ private string one; private string two; private string three; public mykey(sting one,string two, string three){ this.one=one; this.two=two; this.three=three; } //getter @override public int hashcode(){ // creating hashcode } @override public boolean equals(object o){ // comparing } }
=> map<mykey, object>
or using map within map within map:
=> map<string, map<string, map<string, object>>>
i think should go first option. reason beingness more clean , flexible. imagine few months downwards line need add together element key, construction invalid since requires 1 more level of nesting, not mention making more complex.
java
No comments:
Post a Comment