ExceptionFilter.java


Below is the syntax highlighted version of ExceptionFilter.java from §4.4 Symbol Tables.


/******************************************************************************
 *  Compilation:  javac ExceptionFilter.java
 *  Execution:    java ExceptionFilter words.txt < file.txt
 *  Dependencies: SET In.java StdIn.java
 *
 *  Read in a list of words from a file. Then read in a list of
 *  words from standard input and print out all those words that
 *  are not in the first file.
 *
 ******************************************************************************/

public class ExceptionFilter {
    public static void main(String[] args) {
        SET<String> set = new SET<String>();

        // read in strings and add to set
        In in = new In(args[0]);
        while (!in.isEmpty()) {
            String word = in.readString();
            set.add(word);
        }

        // read in string from standard input, printing out all exceptions
        while (!StdIn.isEmpty()) {
            String word = StdIn.readString();
            if (!set.contains(word))
                StdOut.println(word);
        }
    }
}


Copyright © 2000–2022, Robert Sedgewick and Kevin Wayne.
Last updated: Thu Aug 11 10:30:21 EDT 2022.