title: CodeHS Java nitro
body: <p><strong>Instructions</strong></p>
  
  <blockquote>
    <p>Your company is doing some data cleanup, and notices that the email list of all users has been getting outdated. For one, there are some users with repeat email addresses, and some of the email accounts no longer exist.</p>
  </blockquote>
  
  <p>Your job is to create a series of methods that can purge some of the old data from the existing email list.</p>
  
  <p>Create static methods in the DataPurge class that can do the following:</p>
  
  <p>removeDuplicates This method takes an email list, and removes the duplicate email values. It also prints to the console which duplicate emails have been removed.</p>
  
  <p>removeAOL This method removes all email addresses from a list that are from aol.com. It notifies the user which email addresses are being removed as well.</p>
  
  <p>containsOnlyEmails This method returns true if all of the data in the email list is actually an email address. We will define something as an email address if it contains the characters @ and .
  Test your methods out in the DataPurgeTester file. You don’t have to change anything there, but the methods should work accordingly!</p>
  
  <p>Their code</p>
  
  <pre><code>import java.util.ArrayList;
  
  public class DataPurgeTester
  {
      public static void main(String[] args)
      {
          ArrayList&lt;String&gt; emails = new ArrayList&lt;String&gt;();
          addEmails(emails);
          System.out.println("List is all emails: " +DataPurge.containsOnlyEmails(emails));
          DataPurge.removeDuplicates(emails);
          DataPurge.removeAOL(emails);
          System.out.println(emails);
      }
  
  
  
      public static void addEmails(ArrayList&lt;String&gt; emails)
      {
          emails.add("tbmaddux@icloud.com");
          emails.add("rfisher@outlook.com");
          emails.add("anicolao@verizon.net");
          emails.add("openldap@me.com");
          emails.add("improv@gmail.com");
          emails.add("alias@sbcglobal.net");
          emails.add("portele@me.com");
          emails.add("doormat@icloud.com");
          emails.add("mailarc@aol.com");
          emails.add("portele@me.com");
          emails.add("rmcfarla@optonline.net");
          emails.add("chrisk@verizon.net");
          emails.add("gordonjcp@aol.com");
          emails.add("improv@gmail.com");
      }
  }
  </code></pre>
  
  <p>My Code </p>
  
  <pre><code>import java.util.ArrayList;
  
  public class DataPurge
  {
      public static void removeDuplicates(ArrayList&lt;String&gt; e)
      {
          String removed = "";
          for (int i = 0; i &lt; e.size(); i++)
          {
            for (int x = 0; x &lt; e.size(); x++)
            {
                if (e.get(i).equals(e.get(x)))
                {
                    removed += e.get(x) + "\n";
                    e.remove(x);
                }
            }
          }
          System.out.println(removed);
      }
      public static void removeAOL(ArrayList&lt;String&gt; e)
      {
         String removed = "";
          for (int i = 0; i &lt; e.size(); i++)
          {
              String e2 = e.get(i);
  
             if(e2.indexOf("aol.com") != -1)
             {
                 removed += e.get(i) + "\n";
                 e.remove(i);
             }
          }
      }
      public static Boolean containsOnlyEmails(ArrayList&lt;String&gt; e)
      {
          int x = 0;
          for(int i = 0; i &lt; e.size(); i++)
          {
            if (e.get(i).indexOf("@") != -1 &amp;&amp; e.get(i).indexOf(".") != -1) 
            {
                x++;
            }
          }
          return (x == e.size());
      }
  }
  </code></pre>
  
  <p>Problems</p>
  
  <p><a href="https://i.stack.imgur.com/bmq99.png" rel="nofollow noreferrer">https://i.stack.imgur.com/bmq99.png</a>
    <a href="https://i.stack.imgur.com/mtQUt.png" rel="nofollow noreferrer">https://i.stack.imgur.com/mtQUt.png</a></p>