Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions contents/how-can-i-initialize-a-static-map.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,23 @@

我喜欢用Guava(是 Collection 框架的增强)的方法初始化一个静态的,不可改变的map

static fianl Map<Integer, String> myMap = ImmutablMap.of(
1,"one",
2, "two"
)
static final Map<Integer, String> MY_MAP = ImmutableMap.of(
1, "one",
2, "two"
);

·
当map的 entry个数超过5个时,你就不能使用`ImmutableMap.of`。可以试试`ImmutableMap.bulider()`

static fianl Map<Integer, String> myMap = ImmutableMap.<Integer, String>builder()
{
.put(1, "one")
.put(2, "two")

.put(15, "fifteen")
.build();
}
static final Map<Integer, String> MY_MAP = ImmutableMap.<Integer, String>builder()
.put(1, "one")
.put(2, "two")
// ...
.put(15, "fifteen")
.build();



# 原文链接 #

http://stackoverflow.com/questions/507602/how-can-i-initialize-a-static-map
http://stackoverflow.com/questions/507602/how-can-i-initialize-a-static-map