title: Java Remove Duplicates from an Array?
body: <p>I am supposed to read in a file containing many different email addresses and print them out using an array. The problem is I need to eliminate duplicate emails. </p>
  
  <p>I was able to get my try / catch working and print out the email addresses. However, I am not sure how to go about removing the duplicates. I do not have an understanding of hashcode's or how to use a <code>Set</code> yet. Any assistance would be appreciated.</p>
  
  <p>Here is what I have so far:</p>
  
  <pre><code>import java.util.Scanner;
  import java.io.*;
  
  public class Duplicate {
     public static void main(String[] args) {
  
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Enter file name: ");
        String fileName = keyboard.nextLine();
        if (fileName.equals("")) {
           System.out.println("Error: User did not specify a file name.");
        } else {
           Scanner inputStream = null;
  
           try {
              inputStream = new Scanner(new File(fileName));
           } catch (FileNotFoundException e) {
              System.out.println("Error: " + fileName + " does not exist.");
              System.exit(0);
           }
  
           String[] address = new String[100];
  
           int i = 0;
           while (inputStream.hasNextLine()) {
              String email = inputStream.nextLine();
              // System.out.println(email);
  
              address[i] = email;
              System.out.println(address[i]);
              i++;
           }
        }
     }
  }
  </code></pre>