如何给静态值HashMap类? [英] How to give the static value to HashMap?
本文介绍了如何给静态值HashMap类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的HashMap这样的:
I have HashMap like:
static HashMap<String,ArrayList<Media>> mediaListWithCategory=new HashMap<String,ArrayList<Media>>();
我有这样值:
January:
-Sunday
-Monday
Februsry:
-Saturday
-Sunday
-Thursday
March:
-Monday
-Tuesday
-Wednesday
如何定义哈希表,当我静态分配这些价值?
How can I statically assign these values when defining the hash map?
推荐答案
您可以在静态块填充它:
You can populate it in a static block:
static {
map.put("January", Arrays.asList(new Media("Sunday"), new Media("Monday")));
}
(你应该preFER接口,具体的类定义类型地图&LT;字符串列表&LT;媒体与GT;&GT;
)
这篇关于如何给静态值HashMap类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文