Here you can find the source of removeCommonWords(String[] words)
public static final String[] removeCommonWords(String[] words)
//package com.java2s; import java.util.*; public class Main { /**/*from w w w. j a va 2s .com*/ * Initialization lock for the whole class. Init's only happen once per * class load so this shouldn't be a bottleneck. */ private static Object initLock = new Object(); /** * A list of some of the most common words. For searching and indexing, we * often want to filter out these words since they just confuse searches. * The list was not created scientifically so may be incomplete :) */ private static final String[] commonWords = new String[] { "a", "and", "as", "at", "be", "do", "i", "if", "in", "is", "it", "so", "the", "to" }; private static Map commonWordsMap = null; /** * Returns a new String array with some of the most common English words * removed. The specific words removed are: a, and, as, at, be, do, i, if, * in, is, it, so, the, to */ public static final String[] removeCommonWords(String[] words) { // See if common words map has been initialized. We don't statically // initialize it to save some memory. Even though this a small savings, // it adds up with hundreds of classes being loaded. if (commonWordsMap == null) { synchronized (initLock) { if (commonWordsMap == null) { commonWordsMap = new HashMap(); for (int i = 0; i < commonWords.length; i++) { commonWordsMap.put(commonWords[i], commonWords[i]); } } } } // Now, add all words that aren't in the common map to results ArrayList results = new ArrayList(words.length); for (int i = 0; i < words.length; i++) { if (!commonWordsMap.containsKey(words[i])) { results.add(words[i]); } } return (String[]) results.toArray(new String[results.size()]); } }