This is mainly a performance questions. I have a master list of all users existing in a String array AllUids. I also have a list of all end dated users existing in a String array EndUids.
I am working in Java and my goal is to remove any users that exist in the end dated array from the master list AllUids. I know PHP has a function called array_diff.
I was curious if Java has anything that will compare two arrays and remove elements that are similar in both. My objective is performance here which is why I asked about a built in function. I do not want to add any special packages.
I thought about writing a recursive function but it just seems like it will be inefficient. There are thousands of users in both lists. In order to exist in the end dated list, you must exist in the AllUids list, that is until removed.
Example:
String[] AllUids = {"Joe", "Tom", "Dan", "Bill", "Hector", "Ron"};
String[] EndUids = {"Dan", "Hector", "Ron"};
Functionality I am looking for:
String[] ActiveUids = AllUids.RemoveSimilar(EndUids);
ActiveUids would look like this:
{"Joe", "Tom", "Bill"}
Thank you all,
Obviously I can come up with loops and such but I am not confident that it will be efficient. This is something that will run on production machines everyday.
Commons Collections has a class called CollectionUtils and a static method called removeAll which takes an initial list and a list of thing to remove from that list:
That should do what you want provided you use lists of users rather than arrays. You can convert your array into a list very easily with Arrays.asList() so…
EDIT: I also did a bit of digging with this into Commons Collections and found the following solution with ListUtils in Commons Collections as well:
Pretty neat…