Java中定义Map常量,List常量


一般的方式的使用静态代码块。比如:

public final static Map map = new HashMap();  
static {  
    map.put("key1", "value1");  
    map.put("key2", "value2");  
}

下面为一种简单定义Map常量的方式

public final static Map<String, Fragment> NAV_ITEM_ADPTER = new HashMap<String, Fragment>() {
    {
        put("拍录传", new CameraFragment());
        put("集群对讲", new GroupTalkFragment());
        put("视通", new VideoCallFragment());
        put("位置", new PositionFragment());
        put("浏览", new BrowseFragment());
        put("消息", new MsgFragment());
        put("群组", new GroupFragment());
        put("设置", null);
        put("退出", null);
    }
};

List的话则可以这样定义:

public final static List<String> LIST = Arrays.asList("one","two","three");  

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM