所以我收到了一组电子邮件,我应该阅读它们,将它们存储在一个数组中,删除重复项,然后打印“剩菜”。我几乎可以做到这一点,但是在删除重复项后,当我打印剩菜时,它会打印一个额外的null
.
这是我的代码。有人可以指出我修复它的方向吗?
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);
}