code: public static String[] intersect(
        Comparator<? super String> comparator, String[] first, String[] second) {
      List<String> result = new ArrayList<>();
      for (String a : first) {
        for (String b : second) {
          if (comparator.compare(a, b) == 0) {
            result.add(a);
            break;
          }
        }
      }
      return result.toArray(new String[0]);
    }
docs: Returns an array containing only elements found in {@code first} and also in {@code
  second}. The returned elements are in the same order as in {@code first}.