The elipsis ( ...) operator can only be used in method signatures. You can explicitly declare and create arrays:
Map<String, String[]> hm = new HashMap<>();
hm.put("Zara", new String[]{"Pony", "Cars", "Magic"});
hm.put("John", new String[]{"Horse", "Flying", "Loving"});
If you absolutely must use varags, you can bind a call to Map#putyour method:
public static void main(String[] args) {
Map<String, String[]> hm = new HashMap<>();
addToMap(hm, "Zara", "Pony", "Cars", "Magic");
addToMap(hm, "John", "Horse", "Flying", "Loving");
}
private static void addToMap
(Map<String, String[]> map, String key, String... values) {
map.put(key, values);
}
source
share