Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package DataStructures.Easy.Sets;
- import java.util.HashSet;
- import java.util.Iterator;
- public class Sets {
- public static void main(String[] args) {
- HashSet<String> fullList = new HashSet<String>();
- fullList.add("person1@gmail.com");
- fullList.add("person2@gmail.com");
- fullList.add("person3@gmail.com");
- fullList.add("person4@gmail.com");
- fullList.add("person5@gmail.com");
- HashSet<String> sentList = new HashSet<String>();
- sentList.add("person2@gmail.com");
- sentList.add("person3@gmail.com");
- HashSet<String> remainingList = new HashSet<String>();
- Iterator<String> iter = fullList.iterator();
- while (iter.hasNext()) {
- String nextEmail = iter.next();
- if (!Contains(sentList, nextEmail)) {
- remainingList.add(nextEmail);
- }
- }
- System.out.println("Send emails to the following: ");
- iter = remainingList.iterator();
- while (iter.hasNext()) {
- System.out.println(iter.next());
- }
- }
- private static boolean Contains(HashSet<String> sentList, String str) {
- return sentList.contains(str);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement