code: public static <T> List<T> last(List<T> elements, int limit) {
          ArrayList<T> res = new ArrayList<T>();
          for (int i = 0; i < elements.size(); i++) {
              if (res.size() >= limit) {
                  break;
              }
              res.add(elements.get(elements.size() - 1 - i));
          }
          return res;
      }
docs: Getting last elements of list in reverse order
  
  @param elements source list
  @param limit    maximum elements count
  @param <T>      type of objects
  @return result list