Старый вопрос, но, возможно, полезный для тех, кто использует основные библиотеки только как Google Guava.
private static <K, V> Map<K, List<V>> asView(Map<K, V[]> map) {
// returns a view of the given map so it's considered cheap during construction
// may be expensive on multiple re-iterations
return transformEntries(map, new EntryTransformer<K, V[], List<V>>() {
@Override
public List<V> transformEntry(K key, V[] value) {
return asList(value);
}
});
// java 8: return transformEntries(map, (k, v) -> asList(v));
}
...
final Map<String, String[]> map = ImmutableMap.of(
"one", new String[] {"a", "b", "c"},
"two", new String[] {"d", "e", "f"},
"three",new String[] {"g", "h", "i"}
);
final Map<String, List<String>> view = asView(map);
System.out.println(map);
System.out.println(view);
Пример вывода:
{one=[Ljava.lang.String;@4a4e79f1, two=[Ljava.lang.String;@6627e353, three=[Ljava.lang.String;@44bd928a}
{one=[a, b, c], two=[d, e, f], three=[g, h, i]}
Обратите внимание, что вывод является заданным по умолчанию форматированием JDK.