Source of HashSetAddRemoveResult.java


  1: //HashSetAddRemoveResult.java

  3: import java.util.HashSet;

  5: public class HashSetAddRemoveResult
  6: {
  7:     public static void main(String[] args)
  8:     {
  9:         HashSet<String> ownedBooks = new HashSet<String>();
 10:         boolean addResult;
 11:         boolean removeResult;

 13:         ownedBooks.add("A Tale of Two Cities");
 14:         ownedBooks.add("The Lord of the Rings");
 15:         ownedBooks.add("Le Petit Prince");

 17:         addResult = ownedBooks.add("Le Petit Prince");
 18:         System.out.println("Added \"Le Petit Prince\" again: " + addResult);

 20:         removeResult = ownedBooks.remove("The Hobbit");
 21:         System.out.println("Removed \"The Hobbit\": " + removeResult);
 22:     }
 23: }