I have 2 arrays (same size) String[] and Object[].
The question: is there a more elegant way to convert them to Map than this?
private Map<String, Object> arraysToMap(String[] keys, Object[] values) {
Map<String, Object> map = new HashMap<>();
if (keys.length != 0) {
for (int i = 0; i < keys.length; i++) {
map.put(keys[i], values[i]);
}
}
return map;
}
Java 8 style maybe?
Important notes:
valuesmay contain null valuekeyscontains non-null unique elements
ArrayIndexOutOfBoundsException