import java.util.*; // // This uses a HashSet rather than ArrayList // Spot the differences! // public class TestHS { public static void main(String[] args) { String commands = "HashSet Tester (version 299792458) \n" + "add (+), remove (-), contains (?), clear, size, show, help, quit (q)"; System.out.println(commands); Scanner sc = new Scanner(System.in); System.out.print("> "); String command = sc.next(); HashSet S = new HashSet(); while (!command.equals("quit") && !command.equals("q")){ if (command.equals("add") || command.equals("+")){ System.out.print(">> "); S.add(sc.next()); } if (command.equals("remove") || command.equals("-")){ System.out.print(">> "); S.remove(sc.next()); } if (command.equals("contains") || command.equals("?")){ System.out.print(">> "); System.out.println(S.contains(sc.next())); } if (command.equals("clear")) S.clear(); if (command.equals("size")) System.out.println(S.size()); if (command.equals("show")) System.out.println(S); if (command.equals("help")) System.out.println(commands); System.out.println(S); System.out.print("> "); command = sc.next(); } } }