Example Using Sets

import java.util.*;

public class CharacterSets {
    public static void main(String[] args) {
        int numArgs = args.length;

        // A set keeping track of all characters previously encountered.
        Set encountered = new HashSet();                              // (1)
        // For each program argument in the command line ...
        for (int i=0; i
Running the program with the following arguments:
java CharacterSets i said i am maids
results in the following output:
[i] and [] are disjunct.
[d, a, s, i] is a superset of [i]
[i] is a subset of [d, a, s, i]
[a, m] and [d, a, s, i] have [a] in common.
[d, a, s, m, i] is equivalent to [d, a, s, m, i]

No comments:

Post a Comment