Advertisement
Guest User

Untitled

a guest
Sep 18th, 2017
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. package DataStructures.Easy.Sets;
  2.  
  3. import java.util.HashSet;
  4. import java.util.Iterator;
  5.  
  6. public class Sets {
  7.  
  8.     public static void main(String[] args) {
  9.  
  10.         HashSet<String> fullList = new HashSet<String>();
  11.         fullList.add("person1@gmail.com");
  12.         fullList.add("person2@gmail.com");
  13.         fullList.add("person3@gmail.com");
  14.         fullList.add("person4@gmail.com");
  15.         fullList.add("person5@gmail.com");
  16.  
  17.         HashSet<String> sentList = new HashSet<String>();
  18.         sentList.add("person2@gmail.com");
  19.         sentList.add("person3@gmail.com");
  20.  
  21.         HashSet<String> remainingList = new HashSet<String>();
  22.  
  23.         Iterator<String> iter = fullList.iterator();
  24.  
  25.         while (iter.hasNext()) {
  26.             String nextEmail = iter.next();
  27.             if (!Contains(sentList, nextEmail)) {
  28.                 remainingList.add(nextEmail);
  29.             }
  30.         }
  31.  
  32.         System.out.println("Send emails to the following: ");
  33.         iter = remainingList.iterator();
  34.         while (iter.hasNext()) {
  35.             System.out.println(iter.next());
  36.         }
  37.  
  38.     }
  39.  
  40.     private static boolean Contains(HashSet<String> sentList, String str) {
  41.         return sentList.contains(str);
  42.     }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement