public <KResult, VResult> MapArray<KResult, VResult> toMapArray(
     BiFunction<K, V, KResult> key, BiFunction<K, V, VResult> value) {
   MapArray<KResult, VResult> result = new MapArray<>();
   for (Pair<K, V> pair : pairs)
     result.add(key.apply(pair.key, pair.value), value.apply(pair.key, pair.value));
   return result;
 }
 public static <Key, Value> MapArray<Key, Value> toMapArray(Map<Key, Value> map) {
   MapArray<Key, Value> mapArray = new MapArray<>();
   for (Map.Entry<Key, Value> e : map.entrySet()) mapArray.add(e.getKey(), e.getValue());
   return mapArray;
 }
 public static <T> MapArray<Integer, T> toMapArray(Collection<T> collection) {
   MapArray<Integer, T> mapArray = new MapArray<>();
   int i = 0;
   for (T t : collection) mapArray.add(i++, t);
   return mapArray;
 }
 public MapArray(MapArray<K, V> mapArray) {
   this();
   addAll(mapArray.stream().collect(toList()));
 }
 public <VResult> MapArray<K, VResult> toMapArray(Function<V, VResult> value) {
   MapArray<K, VResult> result = new MapArray<>();
   for (Pair<K, V> pair : pairs) result.add(pair.key, value.apply(pair.value));
   return result;
 }