code: public static <T> Collector<T, ?, List<T>> tail(int n) {
          if (n <= 0)
              return empty();
          return Collector.<T, Deque<T>, List<T>> of(ArrayDeque::new, (acc, t) -> {
              if (acc.size() == n)
                  acc.pollFirst();
              acc.addLast(t);
          }, (acc1, acc2) -> {
              while (acc2.size() < n && !acc1.isEmpty()) {
                  acc2.addFirst(acc1.pollLast());
              }
              return acc2;
          }, ArrayList::new);
      }
docs: Returns a {@code Collector} which collects at most specified number of
  the last stream elements into the {@link List}.
  
  <p>
  There are no guarantees on the type, mutability, serializability, or
  thread-safety of the {@code List} returned.
  
  <p>
  When supplied {@code n} is less or equal to zero, this method returns a
  <a href="package-summary.html#ShortCircuitReduction">short-circuiting
  collector</a> which ignores the input and produces an empty list.
  
  @param <T> the type of the input elements
  @param n maximum number of stream elements to preserve
  @return a collector which returns a {@code List} containing the last n
  stream elements or less if the stream was shorter.