E-mail addresses and filtering duplication

Duplicate address
I have a stand alone application that I wrote in Java to read email addresses from a csv file into a buffer and then it is supposed to filter out any duplicates, then write the unique smtp addresses into a new csv file to be veiwed in Excel.
However, this does not work. It is sending all the addresses to the new csv file so I am unsure what I have done wrong.
I belive the issue may be down to the delimiter.
Please see my code below:
import java.io.*;
import java.util.*;
class IS_CustSurvey
     public static void main(String[] args) throws Exception
          String dirName = "c:\\CustReps";          // New string to hold directory path
          String file = "c:\\CustReps\\today.csv";// New string to hold path to input file
          String put = "c:\\CustReps\\report.csv";// New string to hold path of output file
          File out = new File(put);                    // File pointer to output file
          String tmpString = new String();          // New string object
          String InputString = new String();          // New string object
          Random Selection = new Random();          // New math object
          Set MySet = new HashSet();           // New collection
          int dupCount = 0; // Set duplicate counter to zero
          int USC = 0;          // Set the unique string counter to zero
          int i = 0;               // Initialize integer i to zero
          int pcnt = 60; // The default percentage is 60%
          try
                    File dir = new File(dirName);     // File object for directory
                    if(!dir.exists())                    // If directory does not exist
                         dir.mkdir();
                    }                         // ...create it
                    else
                         if(!dir.isDirectory())
                              System.err.println(dirName + " is not a directory");
                              return;
                    File aFile = new File(dir, "report.csv");     // File object for directory
                    if(!aFile.exists())                    // If file does not exist
                         aFile.createNewFile();
                    }                         // ...create it
                    else
                         if(!aFile.isFile())          //If it's not a file...i.e. a directory,
                         {                         //a corrupted file or a non compatable source
                              System.err.println(aFile + " is not a file");//This message is displayed
                              return;
                    File bFile = new File(dir, "today.csv");//Check to see if the file is there
                    if(!bFile.exists())
                         System.out.println("Please put the file today.txt in the CustReps folder");//If the file is not there ask for it
                    else
                         if(!bFile.isFile())     // If it's not a file...as above
                              System.err.println(bFile + " is not a file");
                              return;
               catch(Exception e)
                    e.printStackTrace();
                              // Create a BufferedReader for the input file
          BufferedReader br = new myFileReader("C:\\CustReps\\today.csv").getFile();
          while((InputString = br.readLine()) != null)//Read in a line while there is data
               tmpString += InputString;
          String MyString[] = tmpString.split("\"");//Split the data & put it into an array
          int count = MyString.length;     //Get the length of the array
          // look for duplicates here.
          for(int lc1 = 0; lc1 < count; lc1++)//Loop counter 1 for
               for(int lc2 = (lc1+1);lc2 < count; lc2++)//Loop counter 2 for
                    if(MyString[lc1].matches(MyString[lc2]))//Compare lc1 with lc2
                         if(!MyString[lc1].matches("Empty"))
                              MyString[lc2] = "Empty";//Put empty into the elements in lc2
                              dupCount++;     //Increment the duplicate counter
          USC     = (count-dupCount); // Make the Unique String Counter equal to
                                        // all elements minus the duplicate count
          String UniqueString[] = new String[USC]; // Make a new string array with
                                                            // the value of the Unique String Counter
          // Create new string array...
          for(int lc = 0;lc < USC; lc++)// The loop counter for the Unique String Counter
               if(!MyString[lc].matches("Empty"))//Loop for non emptys
                    UniqueString[i++] = MyString[lc];
          int prcnt = ((USC*pcnt) /100);// Percent = the Unique String Counter multiplied by 10
                                                  // and divided by 100 to get ten percent
          if((prcnt <= 0) && (count > 0)) // If 10 percent is less than zero & the total array
          {                                             //is greater than zero
            prcnt = 1;                              //Percent equals one.
          System.out.println("Array size = " + USC); //Display the amount of unique elements
          System.out.println("10 Percent = " + prcnt);//Display ten percent of them
          int idx = 0; //Set index to zero
          // Should loop from 0 to prcnt...
          for(int lc = 0;lc < prcnt; lc++)
               do
                    idx = Selection.nextInt(USC);
                    BufferedWriter bw = new BufferedWriter(new FileWriter(out.getPath(), true));
                    PrintWriter pw = new PrintWriter(bw);
                    pw.println(UniqueString[idx]);
                    pw.close();
               }while(!MySet.add(UniqueString[idx]));
               System.out.println(UniqueString[idx]);          
class myFileReader
     private String file = null;
     myFileReader(String InPath)
          this.file = InPath;
     public BufferedReader getFile() throws Exception
          BufferedReader br = new BufferedReader(new FileReader(file));
          return(br);
}Any help would be really appreciated.

Instead of matches use equals. You can also join the two if statements into one like this
if (MyString[lc1].equals(MyString[lc2] && !MyString[lc1].equals("Empty"))
Also consider using toUpperCase/toLowerCase and using other kinds of collections. I am not sure of the name of one of them which doesn't require specifying a size (ArrayList) to add unique emails addresses when the above statement (if statement) is true instead of starting a new loop.

Similar Messages

  • My husband and I share the same e-mail address, and computer. We both have iPhones now and want to have our own individual Apple ids, but have one iTunes account is it possible?

    My husband and I share a computer, have the same e-mail address, and have one iTunes account. Can we have different Apple ids on our individual iPhones or do we have to use the same one?

    For purchasing from the iTunes and App stores, you will probably want to share the same Apple ID.  But for other services such as iMessage, FaceTime and iCloud, you should use separate IDs.  For example, if you use the same ID for iMessage you'll start getting each other's text messages.  If you use the same ID for FaceTime you may get each other's FaceTime calls.  If you set up the same iCloud account with the same ID, and data you sync with the account will be merged and the merged data will appear on all devices (i.e., you'll end up with each other's contacts and calendar events).  You would also be sharing the same 5GB of free iCloud storage rather than each having your own 5GB of space.
    This article may be of interest in this regard: http://gigaom.com/apple/itunes-101-multiple-devices-one-itunes-account/.  Also, see this video:http://macmost.com/setting-up-multiple-ios-devices-for-messages-and-facetime.htm l.

  • I need to verify my Apple ID. i know my e-mail address and the password, but what websit do I go to to check for the e-mail. I have a older laptop and my iTunes is 9.1.1 or something and Apple 10.4.11 so how do I do this. Thanks.

    i know my e-mail address and the password, but what website do I go to to check for the e-mail. I have a older laptop and my iTunes is 9.1.1 or something and Apple 10.4.11 so how do I do this. Thanks.

    i know my e-mail address and the password, but what website do I go to to check for the e-mail. I have a older laptop and my iTunes is 9.1.1 or something and Apple 10.4.11 so how do I do this. Thanks.

  • I setup my iCloud account on my iPhone 5 with the wrong e mail address, and I don't remmber the password, I reset my tel and erase all the information on my iPhone in order to try to set up a new iCloud account but when I restart I have a problem aga

    I setup my iCloud account on my iPhone 5 with the wrong e mail address, and I don't remmber the password, I reset my tel and erase all the information on my iPhone in order to try to set up a new iCloud account but when I restart I have a problem agaIn , they ask me to put again the old iCloud user account and password, what I can do in order to start the phone when I don't have the correct e mail and I don't remmber the passcode.?

    I have the same problem as the emails go to my iCloud account that I cannot access!!! I cannot answer the security questions as someone else must have set up my iCloud account. Nothing seems to work. It would be great if someone has some ideas as what can be done to recover the situation?

  • I have three different e-mail addresses, and need to receive the incoming e-mails from the three sources.  How do I enable my iPhone to do it? Tks in advance.

    I have three different e-mail addresses, and need to receive the incoming e-mails from the three sources into my iPhone (it's presently receiving msgs from only one of them).  How do I enable my iPhone to do it? Tks in advance.

    Many thanks for your help!

  • I changed my e-mail address, but everytime I try to do an update on my imac it shows my OLD e-mail address and not the one that I am logged in with, I have tried to rectify this and cant.

    can you please help me to sort this, I changed my e-mail address from [email protected], I have delleted this e-mail now. My new one, [email protected] is now my registered one but everytime I try to do an update in itunes it shows my old e-mail address and it wont use my new one, I own an imac, ipad and iphone, my iphone and ipad are perfectly fine working with [email protected] but not my imac, can you please help me to sort this out. x

    Hi Florafromco,
    You can view your iTunes Store account and request assistance by following the instructions below:
    iTunes Store & Mac App Store: Seeing your purchase history and order numbers
    http://support.apple.com/kb/ht2727
    I hope this information helps ....
    The following article will provide a little more information regarding using multiple Apple ID's:
    Using your Apple ID for Apple services
    http://support.apple.com/kb/HT4895
    I hope this information helps ....
    Have a great day!
    Have a great day!
    - Judy

  • HT204053 how can i delete icloud e-mail address and create another one?

    i made a mistake when created the icloud e-mail address and want to replace that with some other icloud e-mail (not existing yet). how can i do that?

    You can't, without setting up a whole new iCloud account attached to another AppleID.
    You can setup an email alias instead: http://help.apple.com/icloud/#mm6b1a490a

  • I have changed my e-mail address and therefore need to change my apple ID. When I change it to my new address it says it is already my rescue address and cannot be used. Any ideas how to change my rescue address?

    I have changed my e-mail address and therefore need to change my apple ID. When I change it to my new address it says it is already my rescue address and cannot be used. Any ideas how to change my rescue address?

    To change the iCloud ID ("email address") you have to go to Settings>iCloud, tap Delete Account, provide the password for the old ID when prompted to turn off Find My iDevice, then sign back in with the ID you wish to use.  When you do this you may find that the password for your old ID isn't accepted.  If this should happen, and if your old ID is an earlier version of your current ID, you need to temporarily recreate your old ID by going to https://appleid.apple.com, click Manage my Apple ID and sign in with your current iCloud ID.  Click edit next to the primary email account, change it back to your old email address and save the change.  Then edit the name of the account to change it back to your old email address.  You can now use your current password to turn off Find My iDevice on your device, even though it prompts you for the password for your old account ID. Then save any photo stream photos that you wish to keep to your camera roll.  When finished go to Settings>iCloud, tap Delete Account and choose Delete from My iDevice when prompted (your iCloud data will still be in iCloud).  Next, go back to https://appleid.apple.com and change your primary email address and iCloud ID name back to the way it was.  Now you can go to Settings>iCloud and sign in with your current iCloud ID and password.

  • Accessing an Apple account when the e-mail address and birth date are incorrect??

    In updating to IOS yesterday I have stupidly ended up with three Apple accounts (It said I needed one with an e-mail address, there was my cloud account and my account I have used for years to purchase)
    I basically messed up and thought I could create a fresh account with my e-mail address and still cotinue to download updates for my previous purchases.
    Somehow my old Apple account that I bought all my apps on has become disconnected from my e-mail address and has the wrong date of birth - i threfore can't get in to the account or reset the password... is there a number I can call??
    Rspence234

    Good luck with this!!!
    EVEN USING what WAS my Username, this is the exact problem I am having having entered my correct ID and Password.
    Rgds
    Rod

  • After upgrading my iPhone 4S to iOS6, my Find My Friends app no longer links to my Contacts and does not show contact names. It only shows e-mail addresses and does not link up to the corresponding email address in my Contacts. How can I fix this?

    After upgrading my iPhone 4S to iOS6, my Find My Friends app no longer links to my Contacts and does not show contact names. It only shows e-mail addresses and does not link up to the corresponding email address in my Contacts. How can I fix this?

    I am also having problems with a site I am building. No matter what websafe font I use it displays as New Times Roman in FireFox. The correct fonts show in both IE9 and Chrome.
    In addition, text shifts in FireFox. I have to position other text objects farther and farther apart as I go down the page or they start to overlap. Nav buttons and other images also have to be positioned in the wrong place for them to be in the correct place when the page is opened in FireFox. FireFox should display pages correctly by default. I can't expect th average user to have to tweek his/her settings to display my site.
    I have been recommending FireFox on my website as the best browser. I might have to change that and abandon FireFox myself.

  • HT3576 how to assigne a unique sound to a single incoming e mail address and have it aleart when in lock screen 4s Iphone 6.13

    how to assign a unique sound to a single incoming e mail address and have it alert when in lock screen on 4s Iphone 6.1.3
    I receive emergency requests for service thru e mails. my old BB let you assign separate sounds for incoming e mail addresses. can I duplicate that with Iphone or MUST I be woken with each and every incoming e mail?

    I have email messages alert sounds turned off except for VIP addresses (of which I have only one). That means I only get alerted for that one address.
    To add a Contacts entry to VIP senders in iPhone Mail:
    Open your list of mailboxes in iPhone Mail.
    Tap the > button next to VIP.
    Select Add VIP… at the list's end.
    Tap the desired entry from your contacts.
    Then, in Notifications>Mail, turn off the souds for your email account but enable them for VIP.
    Note that all VIP emails will have the same tone. It's more like the Priority feature on a BB than custom text tones.
    Best of luck.

  • Am a new user - iPad3. As my Apple ID I used my Yahoo!Mail address and but used adifferent password to that which I use on Yahoo. In my icloud email account Account shows as my Yahoo mail address but neither my Apple password nor my Yahoo pasword work.

    Am a new user - iPad3. As my Apple ID I used my Yahoo!Mail address and but used adifferent password to that which I use on Yahoo. In my icloud email account Account shows as my Yahoo mail address but neither my Apple password nor my Yahoo pasword work. I am also unable to open any other mail accounts such as gmail. Can anyone help please?

    Sign out and sign in with new Apple ID
    Settings>iTunes and App Store>Apple ID

  • HT5621 how can I delete a primary e-mail addresse and replace it with a excisting Apple ID?

    How can I delete a primary e-mail address and replace it with a excisting Apple ID?

    An email address can only be used one account at a time, so if you want to replace it with an email address that is currently being used on another account then you will need to remove it from that account first before trying to put it on that account. You should be able to change the email address either by logging into your account on your computer's iTunes via the Store > View Account menu option, or via http://appleid.apple.com

  • HT5312 I've forgot security question and answer, how can I add rescue mail address and how can I reset my security question and answer?

    I've forgot security question and answer, how can I add rescue mail address and how can I reset my security question and answer?

    You need to ask Apple to reset your security questions; ways of contacting them include phoning AppleCare and asking for the Account Security team, clicking here and picking a method for your country, and filling out and submitting this form.
    They wouldn't be security questions if they could be bypassed without Apple verifying your identity.
    (105466)

  • I have two e-mail addresses and on the left hand side in mail if i expand the sent box one account has an exclamation mark appeared and some mail has deleted it's self??

    I have two e-mail addresses and on the left hand side in mail if i expand the sent box one account has an exclamation mark appeared and some mail has deleted it's self??

    You can continue to use them as Apple ID's, change the rescue address (as you know)
    You can use your iCloud address, but it won't be an alias, it's a full email address.

Maybe you are looking for

  • Can't use special character "option+5" on german keyboard

    After upgrading to Lion I have problems to select special characters on a german keyboard. Typing in TextEdit  "Option+5" does not display "[". Nothing happens. I always have to use PopChar to insert the "[" character. I already checked out all of th

  • I manually deleted my iphone photos through windows explorer now it wont sync new music or backup. any help please?

    i manually deleted my iphone photos through windows explorer now it wont sync new music or backup. any help please?

  • Tax code and price list not appear automatic

    Hi My Dear, i work in R12.1.1 (solution beacon) -I assigned tax out classification code to an item from the master item,when navigate to sales order and enter the item,the tax code dose not joined with item ,it should be selected from the LOV - also

  • Trouble shooting paper jam

    Any one that can assist, will be  appreciated Printer when printing in "fast print"  option was jammed. I openned the back  panel and pulled out paper that was jammed. Now printer stayed in  the same loop of asking to take out paper jamm and press "o

  • DTP Selection condition

    Hi Experts, I wanted to know if we can read selection conditions maintained in DTP in the start routine using any custom code or using any standard function module. Any help will be appreciated. Thanks,