用Java动态创建哈希映射 [英] Dynamic Creation of Hash Maps in Java
本文介绍了用Java动态创建哈希映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I am doing an application which needs dynamic creation of Hash Maps.
Map<K,V> parent=new Hash Map<K,V>();
if(Some Condition)
{
//Parent map will be added with another sub map
parent = Map<K,Map<K,V>>();
// and So on
}
I need only 3 levels Like this
parent = Map<K,Map<K,Map<K,V>>>();
推荐答案
您究竟想要获得什么?
这是一个3维HashMap。应该在哪里需要?
您需要非常小心键和值 - 不要混淆它们。
但我认为必须有一个更简单的解决方案。
创建一个包含HashMap为2和3的Object怎么样?Dimension?
至少可以减少混淆。
What exactly do you want to acchive?
This is a 3 dimensional HashMap. Where should that be needed?
You need to be very careful with the Keys and the values - do not mix them up.
But I think there must be a simpler solution.
How about creating an Object that holds the HashMap of 2. and 3. Dimension?
Could be at least less confusing.
这篇关于用Java动态创建哈希映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文