public class ExampleClass {
public final static HashMap consts = new HashMap();
static{
constants.put("A", "The Letter A");
constants.put("B", "The Letter B");
constants.put("C", "The Letter C");
}
/* Rest of your class that needs to know the consts */
}
A simple example of how to initialize a static hash map in java
静态HashMap 初始化填充
最新推荐文章于 2024-02-18 22:54:22 发布
本文提供了一个简单的Java示例,展示如何初始化一个静态HashMap。通过在静态初始化块中填充键值对,可以有效地设置常量集合。
1011

被折叠的 条评论
为什么被折叠?



