What I have is an array of String objects called Id, I'm then looping through the Id objects to get the email address associated with that Id (then concatenate them). I now want to remove the String from the array that only has a duplicate email address (ignore by looking at the Id in the String).
For example the String array contains the following Id objects:
{1, 2, 3}
Now I'm concatenating the email address associated with that Id, the String array becomes:
{1 - [email protected], 2 - [email protected], 3 - [email protected]}
So I need to remove duplicate emails (along with the Id concatenated to it) to give me this:
{1 - [email protected], 2 - [email protected]}
Then after that I will remove the email address by using split to give me the final result of:
{1, 2}
So the issue I'm having is, it off course look for the whole string including email and Id, but I need only to look for email address then remove the whole `String from the array.
I've done this bit of code:
//Remove all duplicate email addresses from list
ArrayList<String> duplicateEmails = new ArrayList<String>();
//looping through cform.getConsumers which is a String[] array of Id's, finding email address of that Id and concatenate it and add to the array list
for (String conId : cform.getToConsumers()){
Long consId = Long.parseLong(conId);
Consumer cons = af.getSingleConsumerId(consId);
duplicateEmails.add(conId + " - " + cons.getEmail());
}
//convert arraylist to String array
String[] stringArray = duplicateEmails.toArray(new String[0]);
//remove the duplicates
Set<String> findDuplicates = new HashSet<String>(Arrays.asList(stringArray));
String[] removedEmails = findDuplicates.toArray(new String[0]);