java map常量定義 Java中定義Map常量,List常量
阿新 • • 發佈:2018-11-22
https://www.cnblogs.com/leonxiaosi/p/6928604.html
Java中定義Map常量,List常量
一般的方式的使用靜態程式碼塊。比如:
1 2 3 4 5 |
public
final
static
Map map =
new
HashMap();
static
{
map.put(
"key1"
,
"value1"
);
map.put(
"key2"
,
"value2"
);
} |
下面為一種簡單定義Map常量的方式
1 2 3 4 5 6 7 8 9 10 11 12 13 |
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的話則可以這樣定義:
1 |
public
final
static
List<String> LIST = Arrays.asList(
"one"
,
"two"
,
"three"
);
|
一般的方式的使用靜態程式碼塊。比如:
1 2 3 4 5 |
public
final
static
Map map =
new
HashMap();
static
{
map.put(
"key1"
,
"value1"
);
map.put(
"key2"
,
"value2"
);
}
|
下面為一種簡單定義Map常量的方式
1 2 3 4 5 6 7 8 9 10 11 12 13 |
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的話則可以這樣定義:
1 |
public
final
static
List<String> LIST = Arrays.asList(
"one"
,
"two"
,
"three"
);
|
1 2 3 4 5 |
public
final
static
Map map =
new
HashMap();
static
{
map.put(
"key1"
,
"value1"
);
map.put(
"key2"
,
"value2"
);
}
|
下面為一種簡單定義Map常量的方式
1 2 3 4 5 6 7 8 9 10 11 12 13 |
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的話則可以這樣定義:
1 |
public
final
static
List<String> LIST = Arrays.asList(
"one"
,
"two"
,
"three"
);
|