code: private static void moveElements(List<?> input, Collection<Object> output, int maxElements) {
      for (int i = 0; i < maxElements; i++) {
        output.add(input.remove(0));
      }
    }
docs: Removes at most the given number of available elements from the input list and adds them to the
  given output collection.