code: public static <T> Collection<T> intersect(Collection<T> first,
                                                Collection<T> second) {
          E.checkNotNull(first, "first");
          E.checkNotNull(second, "second");
  
          HashSet<T> results = null;
          if (first instanceof HashSet) {
              @SuppressWarnings("unchecked")
              HashSet<T> clone = (HashSet<T>) ((HashSet<T>) first).clone();
              results = clone;
          } else {
              results = new HashSet<>(first);
          }
          results.retainAll(second);
          return results;
      }
docs: Find the intersection of two collections, the original collections
  will not be modified
  @param first the first collection
  @param second the second collection
  @param <T> element type of collection
  @return intersection of the two collections