How do I map a String to a statically defined array of ints? I tried
private static Map<String, int[]> map = new HashMap<String, int[]>();
static {
map.put("foo", {5, 1, 3, 2});
map.put("bar", {2, 7, 8});
}
which tells me that {5, 1, 3, 2} is illegal.
You need to call the array's constructor before you initialize the content.
map.put("foo", new int[]{5, 1, 3, 2});
Try
private static Map<String, int[]> map = new HashMap<String, int[]>();
static {
map.put("foo", new int[]{5, 1, 3, 2});
map.put("bar", new int[]{2, 7, 8});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With