code: public static <K,V> Map<K,List<V>> groupByKey(List<Pair<K,V>> listInput) {
          Map<K,List<V>> ret = new HashMap<>();
          for(Pair<K,V> pair : listInput) {
              List<V> currList = ret.get(pair.getFirst());
              if(currList == null) {
                  currList = new ArrayList<>();
                  ret.put(pair.getFirst(),currList);
              }
  
              currList.add(pair.getSecond());
          }
  
          return ret;
      }
docs: Group the input pairs by the key of each pair.
  @param listInput the list of pairs to group
  @param <K> the key type
  @param <V> the value type
  @return a map representing a grouping of the
  keys by the given input key type and list of values
  in the grouping.