So I was given a set of emails, and I am supposed to read them in, store them in an array, remove the duplicates, and print the "leftovers". I am almost able to do this, but after removing the duplicates, when I print the leftovers, it prints an extra null
.
Here is my code. Can someone point me in the direction of fixing it?
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];
for(int i=0;inputStream.hasNextLine();i++){
String email = inputStream.nextLine();
address[i]=email.toLowerCase();
//System.out.println(address[i]);
}
Set<String> mail = new HashSet<String>(Arrays.asList(address));
for(String email:mail){
System.out.println(email);
}
homework
tag. – Leigh Apr 8 '12 at 2:48