public static Pattern buildStopwordPattern(Collection<String> stopwords,Boolean caseSensitive){
  StringJoiner sj=new StringJoiner("|");
  for (  String s : stopwords) {
    sj.add(Pattern.quote(s));
  }
  if (caseSensitive) {
    return Pattern.compile("\\b(" + sj.toString() + ")\\b");
  }
 else {
    return Pattern.compile("\\b(" + sj.toString() + ")\\b",Pattern.CASE_INSENSITIVE);
  }
}

public static Pattern buildStopwordPattern ( Collection < String > stopwords , Boolean caseSensitive ) { StringJoiner sj = new StringJoiner ( "|" ) ; for ( String s : stopwords ) { sj . add ( Pattern . quote ( s ) ) ; } if ( caseSensitive ) { return Pattern . compile ( "\\b(" + sj . toString ( ) + ")\\b" ) ; } else { return Pattern . compile ( "\\b(" + sj . toString ( ) + ")\\b" , Pattern . CASE_INSENSITIVE ) ; } }
build a regular expression that will match any stopword
