Hi,
Given 2 arraylists containing string objects of size one million each. Have to find algorythm to find duplicate string objects between 2 array lists.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Hi,
Given 2 arraylists containing string objects of size one million each. Have to find algorythm to find duplicate string objects between 2 array lists.
Concatenate the two arrays together and try to build a heap. If there's a collision on the comparison of any two strings while building the heap, you know that two strings are lexicographically equal. You can throw out one of the duplicates and continue building the heap to find all duplicates (note that you'll have to take into account the fact that the heap size just decreased), or keep both and use an external list to keep track of duplicates. Alternatively, try to do a merge sort of the two arrays. If you run into two strings being equal during the merge portion, you know there's a duplicate. Remove one of them and continue.
A Collection object contains methods that allow one to find unions, intersections, etc... between two (or more) Collection objects. For example, to find Objects identical between two Collection's (in your case Lists), create a new list, add all items from the first list to this object, then call retainAll(), passing the second list. The result is a list containing items that are found in both.
tcstcs (April 18th, 2011)
Thanks Copeg.. I tried with ur idea.. it works perfectly fine.. Thanks a lot..