Java中定義Map常量,List常量,map常量

來源:互聯網
上載者:User

Java中定義Map常量,List常量,map常量

一般的方式的使用靜態代碼塊。比如:

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

  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.