code: public void applyFeatureCountThreshold(int k) {
      float[] counts = getFeatureCounts();
      Index<F> newFeatureIndex = new HashIndex<F>();
  
      int[] featMap = new int[featureIndex.size()];
      for (int i = 0; i < featMap.length; i++) {
        F feat = featureIndex.get(i);
        if (counts[i] >= k) {
          int newIndex = newFeatureIndex.size();
          newFeatureIndex.add(feat);
          featMap[i] = newIndex;
        } else {
          featMap[i] = -1;
        }
        // featureIndex.remove(feat);
      }
  
      featureIndex = newFeatureIndex;
      // counts = null; // This is unnecessary; JVM can clean it up
  
      for (int i = 0; i < size; i++) {
        List<Integer> featList = new ArrayList<Integer>(data[i].length);
        for (int j = 0; j < data[i].length; j++) {
          if (featMap[data[i][j]] >= 0) {
            featList.add(featMap[data[i][j]]);
          }
        }
        data[i] = new int[featList.size()];
        for (int j = 0; j < data[i].length; j++) {
          data[i][j] = featList.get(j);
        }
      }
    }
docs: Applies a feature count threshold to the Dataset.  All features that
  occur fewer than <i>k</i> times are expunged.