I'm currently working on an Android app and I need to translate keys of type String
to Integers
which are determined at compile time of R.raw
.
Right now I have found two ways of creating such a Map
that holds all (needed) values of R.raw
:
private static final Map<String, Integer> map = ImmutableMap.<String, Integer>builder()
.put("...", R.raw.id)
...
.build();
and
private static final Map<String, Integer> map = new ArrayMap<>();
static {
map.put("...", R.raw.id);
...
}
My questions are:
- Are there better ways of creating a
Map
to lookup keys and return values that are determined at compile time? I don't want to use reflection.
and - Which one of those ways would you prefer?