is a HashMap of HashMaps a bad idea?
Hi,
I have a data file to parse through, and when storing the elements of the file, it seems convenient for me to make a HashMap that has a String for a key and a HashMap as a value. Is this a bad idea? I can mess around with ArrayLists and also succeed, but it is not as straightforward as this HashMap idea.
Thanks.
The main thing that occurs to me when I read this, is that you may be throwing out information. For example, if the data file has one record per line and multiple fields per record, and you're putting the fields in a Map, then you're throwing away any information that is derived from the position of the fields.
What is this data? Is it safe to say that it's all aggregations of aggregations?
my data is kind of structured like this:
every node has associated neighbors. there are properties for each neighbor. assume that each node has X neighbors. then for the inner HashMap, there would be X entries. the key would be the neighbor, and the value would be the property.
now, assume that there are Y nodes represented in the file. then there will be Y of these inner HashMaps. so I create the outer HashMap. the key is the node's name and the value is the inner HashMap described above.
my concern is that this may be wasteful to have all these HashMaps?
You're going to need some kind of object to express these relations. I don't know if a HashMap is going to be excessively heavy as these go, but I would suggest not worrying about marginal differences in efficiency like that. I'd suggest being more worried about poor encapsulation and resulting maintenance headaches.