code: public static String[] intersect (String[] a, String[] b) {
          if (a == null || b == null) return null;
          final int maxLength = Math.max(a.length, b.length);// prevent growing of
                                                             // the ArrayList
          final ArrayList<String> intersection = new ArrayList<>(maxLength);
          for (int i = 0; i < a.length; ++i) {
              for (int j = 0; j < b.length; ++j) {
                  if (a[i] == null || b[j] == null) return null;
                  if (a[i].matches(b[j])) {
                      // add element to intersection and check next String in a
                      intersection.add(a[i]);
                      break;
                  }
              }
          }
          String[] result = new String[intersection.size()];
          result = intersection.toArray(result);
          return result;
      }
docs: Returns an array of Strings containing only those String values present in both input String arrays <i>a</i> and
  <i>b</i>.
  <p>
  The order of elements in the returned array equals that in array <i>a</i>.
  <p>
  If <i>a</i> or <i>b</i> or one of their elements is <code>null</code>, <code>null</code> is returned.
  
  @param a an array of Strings (element order will be preserved)
  @param b an array of Strings
  @return an array of shared Strings or <code>null</code>