星空网 > 软件开发 > 操作系统

定义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");  

  




原标题:定义Map常量,List常量

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

爆单攻略:https://www.goluckyvip.com/tag/11593.html
中国电子口岸:https://www.goluckyvip.com/tag/11594.html
跨境包裹:https://www.goluckyvip.com/tag/11595.html
第二季度财报:https://www.goluckyvip.com/tag/11597.html
保税模式:https://www.goluckyvip.com/tag/11598.html
listing禁售:https://www.goluckyvip.com/tag/11599.html
精简版TikTok在法国、西班牙上线,引发欧盟风险质疑:https://www.kjdsnews.com/a/1842206.html
精简版TikTok在法国、西班牙上线,引发欧盟风险质疑:https://www.goluckyvip.com/news/219224.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流