code: @Nullable
    public static <T> T lastElement(@Nullable final Set<T> set) {
      if (CollectionUtils.isEmpty(set)) {
        return null;
      }
      if (set instanceof SortedSet) {
        return ((SortedSet<T>) set).last();
      }
  
      // Full iteration necessary...
      final Iterator<T> it = set.iterator();
      T last = null;
      while (it.hasNext()) {
        last = it.next();
      }
      return last;
    }
docs: Retrieve the last element of the given Set, using {@link SortedSet#last()} or otherwise
  iterating over all elements (assuming a linked set).
  
  @param set the Set to check (may be {@code null} or empty)
  @return the last element, or {@code null} if none
  @since 5.0.3
  @see SortedSet
  @see LinkedHashMap#keySet()
  @see java.util.LinkedHashSet