未知深度Java的嵌套hashmaps [英] nested hashmaps of unknown depth java
问题描述
我有一个需要嵌套的hashmap的需求。但深度将在运行时决定。
例如如果在运行时,用户说3,
,那么我的散列表应该像
HashMap< String,HashMAp< String, HashMap< String,String>>>
如果他说4则
<$ p $ < code> HashMap< String,HashMAp< String,HashMap< String,HashMap< String,String>>>>>
有什么方法可以实现这种功能吗?其他一些API或工具包??
哦,这几乎肯定是一个非常糟糕的主意。 b
你听起来像是你真的想要一棵树或图表,并且不知道如何编写它,所以你正在发明这个表示法,试图使它适用于HashMap。
不要。
您可以通过计算出如何正确编写所需内容来获得更好的效果。
没有库做你想做的事情 - 一个很好的理由 - 你不应该做的。
I have a requirement in which I need to have an nested hashmap. But the depth would be decided at run time. E.g. If at runtime, user says 3, then my hashmap should be like
HashMap<String, HashMAp<String, HashMap<String, String>>>
if he says 4 then
HashMap<String, HashMAp<String, HashMap<String, HashMap<String, String>>>>
Is there any way to implement this kind of functionality? Some other API or toolkit??
Oh, this is almost certainly a very bad idea.
You sound like you really want a tree or graph and don't know how to write it, so you're inventing this notation to try and make it work with HashMap.
Don't.
You'll be better off by figuring out how to write what you need properly.
There's no library to do what you want for a very good reason - you shouldn't.
这篇关于未知深度Java的嵌套hashmaps的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!